700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 在python中输入数据使用input 该函数返回值的类型是_python3的input函数默认返回值都是str...

在python中输入数据使用input 该函数返回值的类型是_python3的input函数默认返回值都是str...

时间:2024-06-26 00:23:02

相关推荐

在python中输入数据使用input 该函数返回值的类型是_python3的input函数默认返回值都是str...

python3的input函数特性

python3与python2的input的区别

使用注意

引例

pwd_list=[2034,2035,2036]

def account_login():

ID=int(input(please input your ID:))

password = input(Password:)

if password == pwd_list[ID] :

print(login success!)

else:

new_pwd=input(enter a new pwd:)

pwd_list[ID]=new_pwd

print(changed)

account_login()

account_login()

我在练习使用python的if结构做登录函数时,出现了问题,通过修改python2还有python3run code找到了区别,上面的例子已经使用了int()转型,是没有问题的。

如果仅使用input输入ID的话,python3运行就会出错,如下

File "/Users/user/存储D/python/02-login_test.py", line 5, in account_login

if password == pwd_list[ID] :

TypeError: list indices must be integers or slices, not str

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。