input有类似c中的scanf函数的功能。
Python2中input使用如下:
>>>x = input("x:")
x: 3
>>>y = input("y:" )
y: 4
>>> print x*y
12
但是Python3中input使用会有如下的提示:
>>> x = input("x:")
x:3
>>> y = input("y:")
y:4
>>> print (x*y)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't multiply sequence by non-int of type 'str'
>>>
原因:
Python3以后的版本中,raw_input和input合体了,取消了raw_input,并用input代替,所以说现在版本的input接受的是字符串,可以如下处理:
>>> x = int(input("x:"))
x:3
>>> y = int(input("y:"))
y:4
>>> print (x*y)
12
最后
以上就是敏感跳跳糖最近收集整理的关于【Python】Python中input的使用的全部内容,更多相关【Python】Python中input内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复