菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
1813
0

python3 和 python2 input 功能的不同点

原创
05/13 14:22
阅读数 2087

python3 和 python2 input的区别:

  • python3会把输入的值当前一个字符串解析
  • python2 被表当前变量来执行

列子

#-*- coding:utf-8 -*-

name = input('你的名字是?')
age = input('你的年龄是?')
qq = input('你的qq是?')

print("======================")
print ('我的名字是%s'%name)
print ('我的年龄是%s'%age)
print ('我的QQ是%s'%qq)
print("======================")

python3运行效果

file

python2运行效果

file

如果在python2中不想输入的值会被当成变量解析.使用raw_input()即可

#-*- coding:utf-8 -*-

name = raw_input('你的名字是?')
age = raw_input('你的年龄是?')
qq = raw_input('你的qq是?')

print("======================")
print ('我的名字是%s'%name)
print ('我的年龄是%s'%age)
print ('我的QQ是%s'%qq)
print("======================")

代码示例:

file

运行效果:

file

发表评论

0/200
1813 点赞
0 评论
收藏
为你推荐 换一批