Python = input()
print(Python)
上面是最基本的,input返回的是str类型
括号内可以添加文本"XXXX"
input(">>>请输入<<<\n")
输出如下:
>>>请输入<<<
它甚至可以
input("""它甚至可以
涵盖print
函数的功能
>""")
输出结果:
它甚至可以
涵盖print
函数的功能
>
上面提到,input()返回的是str类型
那么如果在if中用来比较数怎么办
那么就需要用类型强制转换
如果
Python = input(">>>输入一个数<<<\n")
if Python >= 1:
print(Python)
else:
pass
结果:
>>>输入一个数<<<
886
会出现:
TypeError: '>=' not supported between instances of 'str' and 'int'
而这种形式:
Python = int(input(">>>输入一个数<<<\n"))
if Python >= 1:
print(Python)
else:
pass
结果:
>>>输入一个数<<<
886
886