这篇文章主要介绍python如何使用raw_input()函数,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
raw_input()函数
raw_input():读取输入语句并返回string字符串,输入以换行符结束。
>>> name = raw_input("please input your name:")
please input your name:abc
>>> print(name)
abc
>>> type(name)
<type 'str'>
注意:input()和raw_input()函数的区别:(1)input支持合法python表格式“abc",字符串必须用引号扩起;否则会报语法错误(2) raw_input()将所有输入作为字符串,返回string,而input()输入数字时具有自己的特性,返回输入的数字类型int或float。
#1、语法报错
>>> name = input("input your name:")
input your name:abc
Traceback (most recent call last:)
File "<stdin>",line 1, in <module>
File "<string>",line 1, in <module>
NameError: name 'abc' is not defined
#2、正确输入
>>> name = input("input your name:")
input your name:"abc"
>>> print(name)
abc
#3、input()数据类型
>>> age = input("your age:")
your age:20
>>> type(age)
<type 'int'>
#4、raw_input() 数据类型均为str
>>> age = raw_input("your age:")
your age:20
>>> type(age)
<type 'str'>
以上是“python如何使用raw_input()函数”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://www.toutiao.com/a6590211020759761422