Python input()和raw_input()的區別

 

  區別嘛,就是raw_input()隨便輸都是字符串,而input()必須按照Python的規則來~spa

raw_input()

name=raw_input('輸入姓名:')
age=raw_input('輸入年齡')

咱們輸入漢字的姓名和數字的年齡code

輸入姓名:許嵩
輸入年齡:31
許嵩 31

***Repl Closed***

直接輸,效果槓槓的~可是要注意哦,你的年齡的格式是string哦😯blog

 

input()

name=input('輸入姓名:')
age=input('輸入年齡:')

咱們仍是輸入漢字的姓名和數字的年齡字符串

輸入姓名:'許嵩'
輸入年齡:31
許嵩 31

***Repl Closed***

效果也是槓槓的~可是注意了沒?input()輸入嚴格按照Python的語法,是字符就自覺的加 ' ' ,數字就是數字~input

 

 

啥時候用raw_input()啥時候用input()?

字符的時候能夠用raw_input(),固然不怕麻煩也能夠用input()手動加''string

int類型的時候最好用input()class

總之~你本身看着寫吧~sed

相關文章
相關標籤/搜索