什麼是raw_input
函數?它是一個用戶界面嗎?我們什麼時候使用它?Python中的raw_input函數
回答
它提示用戶(可選arg
raw_input([arg])
),從用戶獲取輸入並返回用戶輸入的數據字符串。請參閱raw_input()
的文檔。
實施例:
name = raw_input("What is your name? ")
print "Hello, %s." % name
此不同之處在於後者試圖解釋由用戶給定的輸入input()
;通常最好避免使用input()
並堅持使用raw_input()
和自定義解析/轉換代碼。
注:這是爲Python 2.x的
「輸入」功能將你輸入就好像它是Python代碼的輸入。 「raw_input」不會轉換輸入並按照給出的輸入進行輸入。建議使用raw_input來處理所有事情。 用法:
>>a = raw_input()
>>5
>>a
>>'5'
如果我的raw_input讓這樣的,沒有喬希或其他任何東西。 這是一個變量,我想,但我不明白她滾:-(
的功能的raw_input提示您輸入和 回報,作爲一個字符串。這當然工作了 我,你再也。噸需要閒置只需打開「DOS提示符」 和運行程序
這是它看起來像我。
C:\temp>type test.py
print "Halt!"
s = raw_input("Who Goes there? ")
print "You may pass,", s
C:\temp>python test.py
Halt!
Who Goes there? Magnus
You may pass, Magnus
我種我的名字和節目後按[Enter
]印製了「誰在那兒?」
raw_input()
更名爲input()
在Python 3
我們可以在兩個版本中使用一個嗎? – chwi 2016-09-14 12:34:40
http://stackoverflow.com/a/7321970/3345375 – jkdev 2016-10-23 15:13:00
這是最有用的答案。 – progyammer 2018-02-18 09:25:19
又如法,混合使用打印的提示,如果你需要讓你的代碼簡單。
格式: -
X =的raw_input() - 這將返回該用戶輸入作爲一個字符串
X = INT(的raw_input()) - 獲取輸入編號作爲從一個的raw_input串()然後使用int()將其轉換爲整數。
print '\nWhat\'s your name ?',
name = raw_input('--> ')
print '\nHow old are you, %s?' % name,
age = int(raw_input())
print '\nHow tall are you (in cms), %s?' % name,
height = int(raw_input())
print '\nHow much do you weigh (in kgs), %s?' % name,
weight = int(raw_input())
print '\nSo, %s is %d years old, %d cms tall and weighs %d kgs.\n' %(
name, age, height, weight)
raw_input是一種輸入形式,它以字符串的形式接受參數,而輸入函數根據您的輸入採用該值。 說,一個=輸入(5)返回一個爲整數值爲5,而 一個=的raw_input(5)返回一個爲 「5」
- 1. raw_input函數中的逗號
- 2. Python:當raw_input無效時重複函數
- 3. python中添加raw_input數
- 4. Python中的線程+ raw_input
- 5. 如何在python raw_input()函數中包含換行符?
- 6. Python:改變raw_input?
- 7. Python:掃描raw_input
- 8. Python raw_input(「」)錯誤
- 9. Python,輸入和raw_input
- 10. python raw_input不工作
- 11. Python 2.7 raw_input腳本
- 12. python中的raw_input沒有按下輸入
- 13. if語句的raw_input和Python中
- 14. Google App Engine shell中的Python raw_input
- 15. 從python中的raw_input打印結果
- 16. Python 2.7 bug中的raw_input輸出「None」
- 17. 中的raw_input Python變量到CMD
- 18. 如何使raw_input調用函數
- 19. python raw_input忽略換行
- 20. Python 2 raw_input列表類型
- 21. python raw_input失敗管道
- 22. Python使用raw_input變量
- 23. Python:將raw_input()轉換爲二進制,然後在函數中使用它
- 24. 在python中使用curses和raw_input
- 25. 在python中使用raw_input作爲列表
- 26. python raw_input()無法粘貼到窗口中?
- 27. 在raw_input python中逃脫*星號
- 28. raw_input()在python 3.1中已棄用?
- 29. 在Python中用raw_input查詢csv
- 30. raw_input中的字母和數字計數
字符串對於Python 3: 名稱=輸入(「什麼是你的名字?「) print(」Hello,%s。「%name) – 2018-02-13 15:02:27