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 使用的更多相关文章

  1. Python input 和 raw_input的区别

    转载[http://www.pythonclub.org/python-basic/input] 使用input 和 raw_input 都可以读取控制台的输入,但是input和raw_input在处 ...

  2. 【每日一个小技巧】Python | input的提示信息换行输出,提示信息用变量表示

    [每日一个小技巧]Python | input的提示信息换行输出,提示信息用变量表示 在书写代码的途中,经常会实现这样功能: 请输入下列选项前的序号: 1.选择1 2.选择2 3.选择3 在pytho ...

  3. python input() 与 raw_input()

    使用input和raw_input都可以读取控制台的输入,但是input和raw_input在处理数字时是有区别的 当输入为纯数字时: input返回的是数值类型,如int,floatraw_inpo ...

  4. Python input()

    在Python语言中,我们经常需要与用户实现交互,下面是一个小实例 # -*- coding:UTF-8 -*- #获取输入参数,并将输入的值存储到txt文件中 String1 = input(&qu ...

  5. python input选择

    例1 import sys #声明字符串数组并初始化 newspaper=['1.北京晚报','2.作家文摘','3.参考消息', \ '4.证券报','5.不需要'] #字符串数组的输出 ): pr ...

  6. python input 与raw_input函数的区别

    转自:http://blog.csdn.net/sruru/article/details/7790436 以前没有深入考虑过raw_input与input函数的区别,所以一直比较困惑,今天测试之后, ...

  7. nyoj 259-茵茵的第一课 (python, input, print)

    259-茵茵的第一课 内存限制:64MB 时间限制:3000ms 特判: No 通过数:23 提交数:36 难度:0 题目描述: 茵茵今年已经六年级了,爸爸给她报了一个学习程序设计的班. 第一节课上, ...

  8. Python input() 函数

    Python3.x 中 input() 函数接受一个标准输入数据,返回为 string 类型. Python2.x 中 input() 相等于 eval(raw_input(prompt)) ,用来获 ...

  9. Python input/output boilerplate for competitive programming

    The following code is my submission for Codeforces 1244C The Football Season. import io import sys i ...

随机推荐

  1. 对百度WebUploader开源上传控件的二次封装,精简前端代码(两句代码搞定上传)

    前言 首先声明一下,我这个是对WebUploader开源上传控件的二次封装,底层还是WebUploader实现的,只是为了更简洁的使用他而已. 下面先介绍一下WebUploader 简介: WebUp ...

  2. Could not evaluate expression

    VS15 调试变量不能显示值,提示:Could not evaluate expression 解决办法: 选择"在调试时显示运行以单击编辑器中的按钮"重启VS即可. 可参考:Vi ...

  3. Effective java笔记(二),所有对象的通用方法

    Object类的所有非final方法(equals.hashCode.toString.clone.finalize)都要遵守通用约定(general contract),否则其它依赖于这些约定的类( ...

  4. .NET应用和AEAI CAS集成详解

    1 概述 数通畅联某综合SOA集成项目的统一身份认证工作,需要第三方系统配合进行单点登录的配置改造,在项目中有需要进行单点登录配置的.NET应用系统,本文专门记录.NET应用和AEAI CAS的集成过 ...

  5. [转载]网站地址栏小图标favicon.ico的制作方法

    有人也许会好奇,有的网址前面有个漂亮的小图标而且有的网站图标还会动,这是怎么做到的呢? 如下图所示: 那个小图标有个名字叫favicon.ico,网站图标虽小但可以起到很好的点缀作用,尤其是当浏览者将 ...

  6. 页面布局class常见命名规范

    头:header 内容:content/container 尾:footer 导航:nav 侧栏:sidebar 栏目:column 页面外围控制整体布局宽度:wrapper 左右中:left rig ...

  7. Spring Boot -- 启动彩蛋

    使用Spring Boot启动的jar包总是会显示一个Spring的图标: . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\_ ...

  8. 正确地编写Objective-C中的便捷方法

    在Objective-C中,如果某个类方法的返回类型就是这个类的实例(例如NSString类中的stringWithFormat:),就可以将这种类方法称为便捷方法(Convenience Metho ...

  9. FastCgi与PHP-fpm之间的关系

    web server(比如说nginx)只是内容的分发者.比如,如果请求/index.html,那么web server会去文件系统中找到这个文件,发送给浏览器,这里分发的是静态数据.好了,如果现在请 ...

  10. springmvc的图片上传与导出显示

    1.前端文件上传需要在form表单内添加enctype="multipart/form-data" ,以二进制传递: 2.web.xml文件内配置 <servlet-mapp ...