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. 数据图表插件Echarts(一)

    一.引言 最近做一个智慧城市项目,项目中需要图表和报表进行数据分析,从网上找了很多,最后找到了百度开放的echarts,一个很强大的插件. 二.介绍 ECharts,缩写来自Enterprise Ch ...

  2. 破解SQLServer for Linux预览版的3.5GB内存限制 (RHEL篇)

    微软发布了SQLServer for Linux,但是安装竟然需要3.5GB内存,这让大部分云主机用户都没办法尝试这个新东西 这篇我将讲解如何破解这个内存限制 要看关键的可以直接跳到第6步,只需要替换 ...

  3. 重新认识了下Entity Framework

    什么是Entity Framework Entity Framework是一个对象关系映射O/RM框架. Entity Framework让开发者可以像操作领域对象(domain-specific o ...

  4. 显示本地openssl支持的加密算法

    参考页面: http://www.yuanjiaocheng.net/webapi/parameter-binding.html http://www.yuanjiaocheng.net/webapi ...

  5. C#关于分页显示

    ---<PS:本人菜鸟,大手子还请高台贵手> 以下是我今天在做分页时所遇到的一个分页显示问题,使用拼写SQL的方式写的,同类型可参考哦~ ------------------------- ...

  6. 无法访问org.springframework.core.NestedRuntimeException 找不到org.springframework.core.NestedRuntimeException的类文件

    在学习springAOP时,出现如下异常: 无法访问org.springframework.core.NestedRuntimeException 找不到org.springframework.cor ...

  7. 解决IE8下不兼容rgba()的解决办法

    rgba()是css3的新属性,所以IE8及以下浏览器不兼容,这怎么办呢?终于我找到了解决办法. 解决办法 我们先来解释以下rgba rgba: rgba的含义,r代表red,g代表green,b代表 ...

  8. H3 BPM:为石化企业提供一个不一样的全停大修平台

    H3 BPM大型炼化企业装置全停检修管理平台(简称"全停大修")结合国际化的流程管理理念.成熟的系统技术架构.优秀的行业解决方案,为石油化工行业全停大修提供了卓越的信息化管理方案, ...

  9. 【教程】SQLite数据库修复

    SQLite 大家都知道,就不多说了. 有时候数据量大了,或者存储过程中出现异常,数据库就可能会出问题. 这是以前公司产品出现过的问题,导致软件都打不开了,我花了不少时间才解决的,趁现在有空贡献出来. ...

  10. 免费SSL证书 之Let’s Encrypt申请与部署(Windows Nginx)

    我着着皇帝的新衣,但是你看不见    有一颗愿意等待的心,说明你对未来充满希望.有一颗充满希望的心,那么等待又算什么.人就是在等待与希望中度过,我们永远要对未来充满信心! 读在最前面: 1.本文案例为 ...