我是靠谱客的博主 敏感跳跳糖,这篇文章主要介绍【Python】Python中input的使用,现在分享给大家,希望可以做个参考。

input有类似c中的scanf函数的功能。

Python2input使用如下:

>>>x = input("x:")
x: 3
>>>y = input("y:" )
y: 4
>>> print x*y
12

但是Python3input使用会有如下的提示:

>>> 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_inputinput合体了,取消了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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(65)

评论列表共有 0 条评论

立即
投稿
返回
顶部