input python2.7_python 中的input
渣渣之路。
一、 在python编程初学者指南中的第六章、使用参数和返回值的例子中:
# -*- coding: utf-8 -*-
def display(message):
print message
def give_me_five():
five = 5
return five
def ask_yes_no(question):
"""
Ask a yes or no questions.
"""
response = None
while response not in ('y', 'n'):
response = input(question).lower()
return response
display("here is a message for you\n")
number = give_me_five()
print "Here's what I got from give_me_five():", number
answer = ask_yes_no("\nPlease enter 'y' or 'n': ")
print "Thank you for entering:", answer
发现自己在pycharm下输入的:y会报错
Please enter 'y' or 'n': y
Traceback (most recent call last):
File "E:/Project/actneed411/furion/static/js/template/testa.py", line 25, in
answer = ask_yes_no("\nPlease enter 'y' or 'n': ")
File "E:/Project/actneed411/furion/static/js/template/testa.py", line 19, in ask_yes_no
response = input(question).lower()
File "", line 1, in
NameError: name 'y' is not defined
但是,输入:'y'或者"y"却是对的:
here is a message for you
Here's what I got from give_me_five(): 5
Please enter 'y' or 'n': 'y' "y"
Thank you for entering: y
二、探究python中的input【1】
由【1】中的文档中,python2.7中输入函数有两种:
1、raw_input():返回的是字符串--string类型,即输入:1+2,返回显示的是:"1+2"
2、input():返回的是数值类型,int,float等,即输入:1+2,返回显示的是:3
而在python3中输入只有一种:
input():返回的是字符串--string类型,没有数值类型了相当于原来的raw_input()
【2】以前有分raw_input和input, raw_input读什么东西都是string, input会解析数据,
版本3合并了raw_input和input, 只能读到string了, 原先的可解析版本不安全,
如果要读到数值,使用类型转换:
a = int(input("a="))
恰好数中使用的是python是python3,这样就能解释通上边的问题了。
------------420 三--
input python2.7_python 中的input相关推荐
- python2 python3 中 raw_input input 区别
1.在python2.x中raw_input( )和input( ),两个函数都存在,其中区别为 raw_input( )---将所有输入作为字符串看待,返回字符串类型 input( )-----只能 ...
- linux 内核 input,初识linux中的input设备
原标题:初识linux中的input设备 究竟何谓input设备,相信市场上卖宠物小狗的大妈都能一口答出来,你能不知道么?对,就是我们传说中的输入设备.说到输入设备,相信用过电脑的兄弟都不会陌生了,即 ...
- html5 规定input域,html5中关于input用法
① url类型 url类型的input元素是一种专门用来输入URL地址的文本框.提交时如果该文本框中的内容不是URL地址格式的文字,则不允许提交. 非url提交时Firefox.Chrome 提示错误 ...
- python3中的 input函数_Python3中的input函数
{"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],&q ...
- Python2中使用input出现的NameError: name ‘***‘ is not defined问题原因及解决办法
上Python官网上查询了一下文档,原因定位如下: Python2中对于input函数来说,它所希望读取到的是一个合法的Python表达式,我的Python版本为2.7,因此出现这个问题,而在Pyth ...
- python中的input函数怎么用_python input()函数怎么用,_Python_ 少侠科技
详细内容 python input()函数怎么用? Python3.x 中 input() 函数接受一个标准输入数据,返回为 string 类型. Python2.x 中 input() 相等于 ev ...
- python 中的input
渣渣之路. 一. 在python编程初学者指南中的第六章.使用参数和返回值的例子中: # -*- coding: utf-8 -*- def display(message): print messa ...
- python中int input_python中的input是什么
Python3.x 中 input() 函数接受一个标准输入数据,返回为 string 类型. Python2.x 中 input() 相等于 eval(raw_input(prompt)) ,用来获 ...
- python中input的功能是什么_python中的input的功能是什么
Python3.x中input()函数接受一个标准输入数据,返回为string类型. Python2.x中input() 相等于eval(raw_input(prompt)),用来获取控制台的输入. ...
最新文章
- 【重磅】AI击败顶级德扑玩家的秘密!德扑AI创造者现身reddit,全面解答34个提问,详解Libratus的现状和未来
- 两个ListBox中的项互相移动及上下移动
- HDU-2044-一只小蜜蜂
- HTML、CSS、JavaScript能实现的功能汇总!
- Web页面减肥,慎用VS的自动格式化功能!
- Linux | 高级I/O函数
- c++ windows 蓝牙库_c++ - “是否有一个多操作系统蓝牙库?”后续:QT Linux到Windows 10蓝牙 - 堆栈内存溢出...
- how to add external library in qt under ubuntu
- SEO原创助手-SEO免费原创助手工具自动分析网站排名
- 一文搞懂函数计算及其工作原理
- div背景颜色设置成渐变色
- 常见的几种手机传感器
- vue项目使用vue-amap调用高德地图api详细步骤
- 信息系统项目管理师必背核心考点(十)信息系统规划
- OpenHarmony如何控制屏幕亮度
- URI API——公交、驾车、步行导航
- vue 自定义指令 directives
- Python入门如何给自己写一个文字小游戏?一只小白的Python游戏
- Servlet监听器实现网站在线人数统计
- Gopher China 2019 讲师专访-滴滴出行/R lab 高级专家工程师杜欢
热门文章
- tableau必知必会之如何在Tableau server中实现工作薄的自动刷新
- MATLAB基本操作(六):矩阵操作的相关函数
- uni-app读取html缓存,uni-app同步缓存值 设置 读取 删除(示例代码)
- model.train_on_batch介绍【TensorFlow2入门手册】
- 深度学习100例-生成对抗网络(DCGAN)手写数字生成 | 第19天
- APACHE TOMCAT INTERVIEW QUESTIONS ANSWERS【转】
- Lucene 中的Tokenizer, TokenFilter学习
- 亿级别记录的mongodb分页查询java代码实现
- Impala:新一代开源大数据分析引擎--转载
- spring jdbctemplate源码跟踪