本文摘自php中文网,作者黄舟,侵删。
实验
如果输入字符串,则马上报错:
1 2 3 4 | 请输入: str
Traceback (most recent call last):
File "<stdin>" , line 1 , in <module>
File "<string>" , line 1 , in <module>
|
但是如果输入整数,却不会报错:
如果把 input
改成 raw_input
,则可以正常记录键盘输入的字符串:
1 | a = raw_input ( '请输入:' ) print a
|
原因
原因就在于,input
只能接受整型输入:
1 | a = input ( '请输入:' ) print type (a)
|
而 raw_input
可以接受字符串输入:
1 | a = raw_input ( '请输入:' ) print type (a)
|
以上就是python:中input()与raw_input()的详解的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
分享一个Python用户名密码登录系统
Python中执行存储过程及获取返回值的方法介绍
Python excel使用xlutils类库实现追加写功能的方法
人生苦短我用Python是什么梗
Python中idle是什么意思
Python软件版本的下载方式
Python是面向对象还是面向过程的
Python的爬虫是什么意思
Python中sqlite3的基本操作实例讲解
Python的消息队列框架介绍
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python:中input()与raw_input()的详解