python2 7與3 5中input的差別

2021-08-20 09:42:44 字數 640 閱讀 9500

在2.7中

input輸入的數值

raw_input輸入的事字串

或者把輸入的內容用引號擴起來

deathage = 80

name = raw_input("your name:")

age = input("your age:")

print

"hi,",name,"your age is ",age,"now."

print

"you can still live for ",deathage-age," years."

在3.5中

input輸入的都是字串

數值要在輸入後轉化成數值型別:

deathage = 80

name = input("your name:")

age = input("your age:")

print

"hi,",name,"your age is ",age,"now."

print

"you can still live for ",deathage-int(age)," years."

python2 7中文編碼 python2 7

我從外部api中獲得了乙個字串 u4ece u8d77 u70b9 u5411 u6b63 u5357 u65b9 u5411 u51fa u53d1,u884c u9a76170 u7c73,u76f4 u884c u8fdb u5165 u4e2d u5173 u6751 u4e1c u8def...

python2 7換行 Python2 7基礎語法

1.建立檔案xx.py usr bin python3 print hello,world 2.linux下執行 python hello.py 3.編碼 預設字串unicode 設定編碼 coding utf 8 4.識別符號 第乙個字元必須是字母表中字母或下劃線 識別符號的其他的部分有字母 數字...

python2 7是什麼 python2 7是什麼

pyton2.7是python在2010年發布的乙個版本。python 是乙個高層次的結合了解釋性 編譯性 互動性和物件導向的指令碼語言,具有很強的可讀性,相比其他語言經常使用英文關鍵字,其他語言的一些標點符號,它具有比其他語言更有特色語法結構。下面來解釋一下python這門語言 python是一種...