1SyntaxError:EOL while scanning string literal
1SyntaxError:unexpected EOF while parsing
1result = (1024+(512*2)/128
1SyntaxError:invalid syntax
1SyntaxError:invalid syntax
1if v=64:
2 print('hello world')
1SyntaxError: can`t assign to keyword
1SyntaxError:invalid syntax
1a = '12345'
2for i in a
3 print(i)
1def sayhi()
2 print('Hi')
1SyntaxError: invalid character in identifier
1print('hello','world')
2# 錯誤原因:逗號是中文標點符號
1for i in range(10):
2# 錯誤原因:冒號是中文標點符號
1IndentationError:unindent does not match any outer indentation level
2IndentationError:expected an indented block
1a = 2
2while a < 0:
3 print('hello')
4 a -= 1
5else:
6 print('0.0')
1NameError: name 'pirnt' is not defined
2NameError: name 'sayhi' is not defined
3NameError: name 'pd' is not defined
1pirnt('hello world')
2# 錯誤原因:print拼寫錯誤。
1sayhi()
2
3def sayhi():
4 pass
5# 錯誤原因:在函數定義之前對函數進行調用。
1pd.read_excel(r'file.xlsx')
2# 錯誤原因:在調用pandas方法前並未導入pandas庫或者並未起別名為pd。
1TypeError: Can`t convert 'int' object to str implicitly
2TypeError: unsupported operand type(s) for + : 'float' and 'str'
1TypeError: input expected at most 1 arguments,got 2
2TypeError: say() missing 1 required positional argument:'words'
1input('輸入姓名','年齡')
2# 錯誤原因:試圖給input()函數提供第2個參數。
1def say(words):
2 print(words)
3
4say()
5# 錯誤原因:調用函數時未傳遞參數。
1d = {'a':1,'b':2}
2print(d['c'])
1IndexError: list index out of range
1a = [1,2,3]
2print(a[3])
3# 錯誤原因:列表a中不存在第4個索引。列表的索引從0開始編號。
1UnboundLocalError: local variable 's' referenced before assignment
1s = 1
2
3def test():
4 s += 1
5 print(s)
6
7test()
8# 錯誤原因:在函數內對未聲明的全局變量s進行了自增操作。
9# Python將變量s視為一個本地的局部變量,但該變量未初始化。
1AttributeError: 'tuple' object has no attribute 'append'
2AttributeError: 'DataFrame' object has no attribute 'col'
1t = (1,2,3)
2t.append(4)
3# 錯誤原因:元祖不可變。
1df = pd.read_excel(r'data.xlsx')
2df.col
3# 錯誤原因:DataFrame沒有col屬性,應該為columns。
1ModuleNotFoundError: No module named 'pandas'
1import pandas as pd
2# 沒有導入成功,報上面錯誤。
1FileNotFoundError: File b'E:\test\test_data.csv' does not exist
1pd.read_csv('E:\test\test_data.csv')
2# 錯誤原因:路徑中包含'\t',系統錯誤地認為是制表符。