Python 中的 raw_input 函数 [英] raw_input function in Python
本文介绍了Python 中的 raw_input 函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是raw_input
函数?它是用户界面吗?我们什么时候使用它?
What is the raw_input
function? Is it a user interface? When do we use it?
推荐答案
它向用户呈现提示(raw_input([arg])
的可选arg
), 获取用户输入并以字符串形式返回用户输入的数据.请参阅 raw_input()
的文档.
It presents a prompt to the user (the optional arg
of raw_input([arg])
), gets input from the user and returns the data input by the user in a string. See the docs for raw_input()
.
示例:
name = raw_input("What is your name? ")
print "Hello, %s." % name
这不同于 input()
因为后者试图解释用户给出的输入;通常最好避免 input()
并坚持使用 raw_input()
和自定义解析/转换代码.
This differs from input()
in that the latter tries to interpret the input given by the user; it is usually best to avoid input()
and to stick with raw_input()
and custom parsing/conversion code.
注意:这是针对 Python 2.x
这篇关于Python 中的 raw_input 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文