Python错误集锦
Python错误集锦
01 未定义
# 1.未定义
print(a)

02 类型不一致
# 2. 类型不一致
b = 'haha'
c = 123
b+c

b+str(c)
'haha123'
c+b

c+int(b)

int('8')
8
03 语法错误
# 3.语法错误
# 符写错了
print(123)

04 露符号
# 漏符号
if 3>2
print(666)

05 太多符号导致遗漏
# 太多符号导致遗漏
int(int(eval('123'))

06 缩进错误
# 4. 缩进错误 ,出现于 if - 循环 -函数 和 class
if 2>1:
print(2)
print(3)

for i in range(5):
print(i)
print(i+1)

07 索引错误
# 5.索引错误
list2 = [1,2,3]
print(list2[3])

08 NoteType错误
# 6. NoteType错误
# 一般发生在我们连写的时候
dict2={'a':'12345','B':'45678'}
dict2.get('a')[-1]
print(dict2.get('b')[-1])

dict2={'a':'12345','B':'45678'}
print(dict2.get('b').find_all('img'))

09 文件关闭,继续写入
# 7.文件关闭,继续写入
with open('1.txt','w') as f:
f.write('123')
f.write('456')

10 权限错误
# 8. 权限错误
# csv,excel被 打开的时候,继续写入就会出现
# Permissions error

浙公网安备 33010602011771号