![图片[1]-python里input怎么解释-uusu优素-乐高,模型,3d打印,编程](http://uusucn.zbbe.cn/wp-content/uploads/2024/01/5d9edba303d30845.jpg)
python中input函数有类似c中的scanf函数的功能。
Python2中input使用如下:
>>>x=input("x:")
x:3
>>>y=input("y:")
y:4
>>>printx*y
12
但是Python3中input使用会有如下的提示:
>>>x=input("x:")
x:3
>>>y=input("y:")
y:4
>>>print(x*y)
Traceback(mostrecentcalllast):
File"<stdin>",line1,in<module>
TypeError:can'tmultiplysequencebynon-intoftype'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原文来自:https://www.py.cn © 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END


















































暂无评论内容