python如何使用raw_input()函数

发布时间:2022-03-30 14:41:26 作者:小新
来源:亿速云 阅读:388

这篇文章主要介绍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()函数”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. 常见Python的Web开发框架有哪些呢
  2. Python和Goland哪个会更好

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

python raw_input()

上一篇:python如何使用input函数

下一篇:python中format()函数有什么用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》