什麼是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. 設置函數調用python中的raw_input
- 2. 如何在Python中使用if函數的raw_input函數?
- 3. raw_input函數中的逗號
- 4. Python:當raw_input無效時重複函數
- 5. cmd中的raw_input Python
- 6. python中添加raw_input數
- 7. raw_input定義函數
- 8. 在R中有一些函數像python中的raw_input()?
- 9. raw_input python
- 10. raw_input Python
- 11. Python raw_input()
- 12. 的raw_input()在Python
- 13. 函數中使用raw_input()的Python縮進錯誤
- 14. Python中的線程+ raw_input
- 15. 回顧Python中的raw_input/input
- 16. raw_input()中的Python EOF錯誤
- 17. 如何在python raw_input()函數中包含換行符?
- 18. python隱藏raw_input
- 19. Python:改變raw_input?
- 20. python raw_input()syntax
- 21. Python:掃描raw_input
- 22. Python raw_input(「」)錯誤
- 23. Python的分鐘()函數不同工作的raw_input轉換爲float
- 24. python訪問raw_input的值作爲參數
- 25. Python EOF錯誤raw_input()
- 26. Python,輸入和raw_input
- 27. python raw_input不工作
- 28. Python:使raw_input執行
- 29. Python 2.7 raw_input腳本
- 30. 的raw_input的Python發行
字符串對於Python 3: 名稱=輸入(「什麼是你的名字?「) print(」Hello,%s。「%name) – 2018-02-13 15:02:27