python小白常見錯誤

2021-10-08 19:49:46 字數 1088 閱讀 3935

nameerror: name 『lower』 is not defined。lower為字串內建函式,使用方法為str.lower(),內建函式為系統已經定義好的,預設可以直接進行呼叫的函式。

syntaxerror: positional argument follows keyword argument 使用print函式的時候,可以設定sep和end兩個引數的形式,sep代表print在輸出多個字串的時候,這些字串之間的間隔符號,一般是空格。end代表列印結束字尾符號,預設為』\n』。但是這些引數的設定都是應該是在print函式的最後,無論是想要輸出的字串引數,還是所謂的format佔位都應該在sep和end的前面

taberror: inconsistent use of tabs and spaces in indentation 貌似在新的python語法當中是不支援tab鍵和四個空格鍵混編,來建立縮排的。最好還是同意標準,直接使用tab鍵簡單又不出錯。

taberror: inconsistent use of tabs and spaces in indentation 同樣是這個錯誤,非迴圈和判斷結構的語句,前面不小心打了個空格,也會導致縮排的不規範,從而報錯

traceback (most recent call last):

file 「f:/python指令碼/random.py」, line 1, in

import random

file 「f:\python指令碼\random.py」, line 3, in

print(random.uniform(1,10))

attributeerror: module 『random』 has no attribute 『uniform』

定義自己寫的檔名為python會和系統自帶的模組產生衝突,並且在寫程式的時候也要注意不要引用python關鍵字作為自己的變數名。

indexerror: string index out of range  字串長度為print(len(str)),打出來為n的話,字串的索引是從零到n-1,那麼在根據字串索引取出字串中的字元時就有可能產生這種錯誤了。

for迴圈,while迴圈和if判斷需要加上引號』:』,忘記加上引號就會出現語法錯誤

Python常見錯誤

1.indentationerror expected an indented block python語言是一款對縮排非常敏感的語言,給很多初學者帶來了困惑,即便是很有經驗的python程式設計師,也可能陷入陷阱當中。最常見的情況是tab和空格的混用會導致錯誤,或者縮排不對,而這是用肉眼無法分別的...

python 常見錯誤

原因 pylint 未安裝 配置正確 解決 pip show pylint 看看版本 settings.json 設定成這樣就好了 python.linting.pylintpath pylint python.pythonpath usr bin python3 使用vscode開發python程...

python常見錯誤

安裝python之後,有時候需檢查python和pip是否安裝成功。在命令列中,輸入python,會反饋當前系統預設的python版本資訊。如果在輸入完python之後,就行輸入pip。則會出現如下列印錯誤 pip traceback most recent call last file line ...