1、在python2.x中raw_input( )和input( ),两个函数都存在,其中区别为

raw_input( )---将所有输入作为字符串看待,返回字符串类型

input( )-----只能接收“数字”的输入,在对待纯数字输入时具有自己的特性,它返回所输入的数字的类型( int, float )

2、在python3.x中raw_input( )和input( )进行了整合,去除了raw_input( ),仅保留了input( )函数,其接收任意任性输入,将所有输入默认为字符串处理,并返回字符串类型。

例如:

Python 2.3.4 (#1, Feb  2 2005, 11:44:13)
[GCC 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> user=raw_input("please input:")
please input:wei               #  raw_input输入  字符串  成功
>>> user
'wei'
>>> user=input("please input:")
please input:123               #  input 输入  数字  成功(返回的是数字)
>>> user
123
>>> user=raw_input("please input:")
please input:111           #  raw_input 输入  数字  成功(返回的还是当成字符串)
>>> user
'111'
>>> user=input("please input:")
please input:wei                          #  input  输入字符串   失败
Traceback (most recent call last):  File "<stdin>", line 1, in ?  File "<string>", line 0, in ?
NameError: name 'wei' is not defined  

在Python 3.2.3中  input和raw_input 整合了,没有了raw_input

Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> user=raw_input("please input:")                 #没有了raw_input
Traceback (most recent call last):  File "<stdin>", line 1, in <module>
NameError: name 'raw_input' is not defined
>>> user=input("please input:")
please input:wei
>>> user
'wei'
>>> user=input("please input:")                     #input的输出结果都是作为字符串
please input:123
>>> user
'123'

python2 python3 中 raw_input input 区别相关推荐

  1. Python2和Python3中raw_input( )和input( )区别(附代码)

    备注: 1.在python2.x中raw_input( )和input( ),两个函数都存在,其中区别为 raw_input( )---将所有输入作为字符串看待,返回字符串类型 input( )--- ...

  2. python3中input输入浅谈_详解Python3中的 input() 函数

    详解Python3中的 input() 函数 一.知识介绍: 1.input() 函数,接收任意输入,将所有输入默认为字符串处理,并返回字符串类型: 2.可以用作文本输入,如用户名,密码框的值输入: ...

  3. python input函数详解_对Python3中的input函数详解

    下面介绍python3中的input函数及其在python2及pyhton3中的不同. python3中的ininput函数,首先利用help(input)函数查看函数信息: 以上信息说明input函 ...

  4. python2和python3中的range区别

    python2中的range返回的是一个列表 python3中的range返回的是一个迭代值 for i in range(1,10)在python2和python3中都可以使用,但是要生成1-10的 ...

  5. input python2.7_python 中的input

    渣渣之路. 一. 在python编程初学者指南中的第六章.使用参数和返回值的例子中: # -*- coding: utf-8 -*- def display(message): print messa ...

  6. python3中的 input函数_Python3中的input函数

    {"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],&q ...

  7. print在python2和python3的区别_Python2和Python3中print的不同点

    在Python2和Python3中都提供print()方法来打印信息,但两个版本间的print稍微有差异 主要体现在以下几个方面: 1.python3中print是一个内置函数,有多个参数,而pyth ...

  8. python 中的input

    渣渣之路. 一. 在python编程初学者指南中的第六章.使用参数和返回值的例子中: # -*- coding: utf-8 -*- def display(message): print messa ...

  9. python3除法运算_Python2和Python3中除法操作/的不同

    X/Y 在3.0版本之前的Python中 >>>1/2 0 即一个整数(无小数部分的数)被另外一个整数除,计算结果的小数部分被截除了,只留下了整数部分 有时候,这个功能比较有用,譬如 ...

最新文章

  1. uvc摄像头代码解析7
  2. 苹果mac电脑修改并快速linux网络配置
  3. linux bash命令_Ultimate Linux命令行指南-Full Bash教程
  4. labview自动生成html,使用LabVIEW实现网页数据提取及交互.pptx
  5. 编程神回复:在学习编程时,你觉得必须读的科学书籍有哪些?
  6. html5声音播放音乐,HTML5 煽情的音乐播放器和音频可视化
  7. 海员可以饮用蒸馏海水吗?
  8. 重庆计算机一级考试在线做,全国(重庆考区)计算机一级考试教程.doc
  9. 弹性计算安全组最佳实践及新特性介绍
  10. 优酷暗黑模式(三):暗黑模式设计指南
  11. 修改Python解释器和包路径
  12. 离散数学与计算机的发展,计算机学科发展中离散数学的作用与运用
  13. Python在数学建模中的简单运用
  14. ubuntu20.04安装Strom集群
  15. N-MOS电平转换电路分析
  16. 安卓开发教你监听手机Home键
  17. EPICS教程3 -- 输入/输出控制器(IOC)的创建
  18. 【CSS】页面背景的毛玻璃效果
  19. iVMS-4200 Vs区别_76840红单足球预测 法甲 21:00 安格斯 VS 梅斯
  20. 温莎大学应用计算机,加拿大留学,温莎大学英语计算机专业了解一下

热门文章

  1. DNS与Active Directory在两台服务器分别布署
  2. 男人心疼女人的十种方式
  3. vue结合php增删改查实例,从vue基础开始创建一个简单的增删改查的实例
  4. FaaS — Serverless Computing(无服务器计算)
  5. PostgreSQL — 外键关联操作
  6. KVM — CPU 虚拟化
  7. sys.stderr.write(f“ERROR: {exc}“) SyntaxError: invalid syntax错误
  8. 编译linux内核报错‘make menuconfig‘ requires the ncurses libraries
  9. Windows Server 2016-Netdom Join加域并指定OU (一)
  10. cf559C. Gerald and Giant Chess(容斥原理)