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