raw_input() 与 input() __ Python
>>> input ("my age is : ")
my age is :23
23
>>> raw_input("my age is : ")
my age is : 23
'23'
有什么不一樣?再看一個例子
>>> age = input(" how old r u ?")
how old r u ?23
>>> print "you are " + age + "!"
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
??? print "you are " + age + "!"
TypeError: cannot concatenate 'str' and 'int' objects
>>> age = raw_input("how old r u? ")
how old r u? 23
>>> print "you are " + age +"!"
you are 23!
input()是把讀入的數據默認為Python expression(額...中文怎么說,python表達式?)
raw_input()是把讀入的數據轉換成String.
所以一般時候我們用來接受用戶輸入的時候,都是使用raw_input()而非input().
?
總結
以上是生活随笔為你收集整理的raw_input() 与 input() __ Python的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: windows下apache报错The
- 下一篇: vs2015提示中文