Python input 使用
Python 3.0 中使用"input" , Python 2.0 中使用"raw_input"
Python 3.5:
#!C:\Program Files\Python35/bin
# -*- conding:utf-8 -*-
# author: Frank
user_input = input("please input your name:") #input 函数的使用
print("User input Msg:", user_input) # 显示结果
>>>please input your name: Frank
User input Msg: Frank
Python 2.7:
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> user_input = input("your name:") # For python2.7 , 这是错误的写法
your name:is
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1
is
^
SyntaxError: unexpected EOF while parsing
>>> user_input = raw_input("your name:") # For python 2.7 , raw_input 是正确的.
your name: Frank
>>> print user_input
Frank
在python3.0 中, input 默认接受的都是 string
eg: 下面的代码将出错
# -*- conding:utf-8 -*-
# author: Frank
name = input("please input your name:")
age = input("please input your age:")
job = input("please input your job:") # 这里用了一个变量Msg,多行模式
Msg = '''
Information of user Frank:%s
------------------------
Name : %s
Age : %d
Job :%s
------------End---------
''' %(name,name, age, job)
print(Msg)
结果出错:
please input your name: frank bian
please input your age:34
please input your job:it
Traceback (most recent call last):
File "<encoding error>", line 16, in <module>
TypeError: %d format: a number is required, not str
Python input 使用的更多相关文章
- Python input 和 raw_input的区别
转载[http://www.pythonclub.org/python-basic/input] 使用input 和 raw_input 都可以读取控制台的输入,但是input和raw_input在处 ...
- 【每日一个小技巧】Python | input的提示信息换行输出,提示信息用变量表示
[每日一个小技巧]Python | input的提示信息换行输出,提示信息用变量表示 在书写代码的途中,经常会实现这样功能: 请输入下列选项前的序号: 1.选择1 2.选择2 3.选择3 在pytho ...
- python input() 与 raw_input()
使用input和raw_input都可以读取控制台的输入,但是input和raw_input在处理数字时是有区别的 当输入为纯数字时: input返回的是数值类型,如int,floatraw_inpo ...
- Python input()
在Python语言中,我们经常需要与用户实现交互,下面是一个小实例 # -*- coding:UTF-8 -*- #获取输入参数,并将输入的值存储到txt文件中 String1 = input(&qu ...
- python input选择
例1 import sys #声明字符串数组并初始化 newspaper=['1.北京晚报','2.作家文摘','3.参考消息', \ '4.证券报','5.不需要'] #字符串数组的输出 ): pr ...
- python input 与raw_input函数的区别
转自:http://blog.csdn.net/sruru/article/details/7790436 以前没有深入考虑过raw_input与input函数的区别,所以一直比较困惑,今天测试之后, ...
- nyoj 259-茵茵的第一课 (python, input, print)
259-茵茵的第一课 内存限制:64MB 时间限制:3000ms 特判: No 通过数:23 提交数:36 难度:0 题目描述: 茵茵今年已经六年级了,爸爸给她报了一个学习程序设计的班. 第一节课上, ...
- Python input() 函数
Python3.x 中 input() 函数接受一个标准输入数据,返回为 string 类型. Python2.x 中 input() 相等于 eval(raw_input(prompt)) ,用来获 ...
- Python input/output boilerplate for competitive programming
The following code is my submission for Codeforces 1244C The Football Season. import io import sys i ...
随机推荐
- 设计模式C#合集--工厂方法模式
简单工厂,代码: public interface ISpeak { public void Say(); } public class Hello : ISpeak { public void Sa ...
- Oracle-BPM安装详解
H3 BPM安装包括两个部分,基础工作包括安装IIS..net Freamwork基础框架.安装完成之后,主要配置安装包括数据库,H3 BPM 程序.下面详细介绍Oracle与H3 BPM对接安装的整 ...
- System进程(pid=4)占用80端口的解决方案
问题 Mail服务器在安装TFS服务(含SQLServer2016)后启动不了网页服务. 排查问题 使用命令查看端口占用情况 netstat -nao | find ":80" n ...
- Selenium-java-获取当前时间
1 获取当前时间 // 获取当前时分秒 Calendar now = Calendar.getInstance(); int is = now.get(Calendar.HOUR_OF_DAY); i ...
- EChart系列:在echart3中使用百度地图扩展之后,如何获取到百度地图对象
最近做项目想要在百度地图上叠加显示echart的散点图,然后根据地图的缩放等级和区域范围要显示不同的散点图,这中间折腾了好久.功能要求包括: (1)底图使用百度地图: (2)可以在地图上叠加显示ech ...
- what's deviceone
DeviceOne技术介绍 一. DeviceOne是什么 DeviceOne(以下简称Do)是一个移动开发的平台或技术,与之对等的是Android移动开发技术,iOS移动开发技术,Windo ...
- 再来说说 LaTeX
在我的上一篇随笔中,我提到了 Markdown.LaTeX 和 MathJax.这几个东西对目前的网络技术文章的写作.展示都有深远的影响.在上一篇中,我还给出了一份 LaTeX 语法的学习资料.在这一 ...
- 白板编程浅谈——Why, What, How
作者:Lucida 微博:@peng_gong 豆瓣:@figure9 原文链接:http://lucida.me/blog/whiteboard-coding-demystified/ 这篇文章节选 ...
- xcode8.1 插件失效的问题
1,查看 Xcode 插件安装目录 ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins 鼠标点一下桌面, command+shi ...
- java https单向认证(忽略认证)并支持http基本认证
https单向认证(忽略认证)并支持http基本认证, 温馨提示 1,jar包要导入对 2,有匿名类编译要注意 3,欢迎提问,拿走不谢!背景知识 Https访问的相关知识中,主要分为单向验证和双向验证 ...