python系统学习日记 L11~L12 python2.x与3.x 输入函数input的区别

这篇博客记录了Python中input函数在2.x和3.x版本的不同,以及它们的使用。在Python 3.x中,input()函数默认返回字符串。附加题探讨了raw_input()在Python 2.x的作用,并展示了如何使用input()进行数值运算。另外,还介绍了pydoc命令,它是一个用于生成和查看Python文档的帮助工具。
摘要由CSDN通过智能技术生成

L11:
书中代码:

print "How old are you?",
age = raw_input()
print "How tall are you?",
height = raw_input()
print "How much do you weigh?",
weight = raw_input()

print "So, you're %r old, %r tall and %r heavy." % (
age, height, weight
)

代码修改为:
print(“How old are you?”)
age = input()
print(“How tall are you?”)
height = input()
print(“How much do you weigh?”)
weight = input()

print("So, you're %r old, %r tall and %r heavy." % (
age, height, weight
))

结果输出:
How old are you?
30
How tall are you?
180
How much do you weigh?
78
So, you’re ‘30’ old, ‘180’ tall and ‘78’ heavy.
附加题:
1、上网查一下 Python 的 raw_input 实现的是什么功能?
python 3.0之后,不区分input()和raw_input(),统一为input(),默认的返回格式为字符串。
2、你能找到它的别的用法吗&

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值