练习python时遇到的小问题
TypeError: unsupported operand type(s) for &: ‘int’ and 'str’
原代码为:
people=["a","b","c","e"]
a=input("请输入你要查的人")
for i in range(0,len(people)):
if a==people[i]:
print("有这个人")
break
if i==(len(people)-1) & a!=people[i]:
print("查无此人")
出现的问题为:
Traceback (most recent call last):
File "one.py", line 7, in <module>
if i==(len(people)-1) & a!=people[i]:
TypeError: unsupported operand type(s) for &: 'int' and 'str'
我的理解是:&两边的变量类型不相同,所以无法进行运算
最后修改为:
for i in range(0,len(people)):
if a==people[i]:
print("有这个人")
break
if (i==len(people)-1) & bool(a!=people[i]):
print("查无此人")
这样两边都变成了bool类型
python小白,请大家多多指教!!!!!