Python提供了两个内置函数从标准输入读入一行文本,默认的标准输入是键盘。如下:
《python之判断数据异常Python读取键盘输入》总结了关于python网站教程,对于我们来www.002pc.com确实能学到不少知识。
raw_input
input
raw_input函数raw_input() 函数从标准输入读取一个行,并返回一个字符串(去掉结尾的换行符):str = raw_input("Enter your input: ");
print "Received input is : ", str
这将提示你输入任意字符串,然后在屏幕上显示相同的字符串。当我输入"Hello Python!",它的输出如下:
Enter your input: Hello Python
Received input is : Hello Python
input函数input() 函数和raw_input() 函数基本可以互换,但是input会假设你的输入是一个有效的Python表达式,并返回运算结果。这应该是两者的最大区别。
str = input("Enter your input: ");
print "Received input is : ", str这会产生如下的对应着输入的结果:
Enter your input: [x*5 for x in range(2,10,2)]
Recieved input is : [10, 20, 30, 40]
更多:python之判断数据异常Python读取键盘输入
https://www.002pc.comhttps://www.002pc.com/python/1713.html
你可能感兴趣的Python,键盘输入,读取
No alive nodes found in your cluster
0踩
赏
0 赞