标签:str stdin 类型转换 a20 微博 相互 pytho 报错 res
# python3
d=float(input(‘Please enter what is your initial balance: \n‘))
p=float(input(‘Please input what is the interest rate (as a number): \n‘))
Please enter what is your initial balance:
50000
Please input what is the interest rate (as a number):
2.3
""
引号引起来,否则会出现错误。# python2
>>>a = input("input:")
input:123 # 输入整数
>>> type(a)
<type ‘int‘> # 整型
>>> a = input("input:")
input:"runoob" # 正确,字符串表达式
>>> type(a)
<type ‘str‘> # 字符串
>>> a = input("input:")
input:runoob # 报错,不是表达式,输入的runoob必须用括号括起来
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name ‘runoob‘ is not defined
<type ‘str‘>
# python2
>>>a = raw_input("input:")
input:123
>>> type(a)
<type ‘str‘> # 字符串
>>> a = raw_input("input:")
input:runoob
>>> type(a)
<type ‘str‘> # 字符串
>>>
标签:str stdin 类型转换 a20 微博 相互 pytho 报错 res
原文地址:https://www.cnblogs.com/cloud-ken/p/12636769.html