《Python程式設計 從入門到實踐》 內容要點

2021-08-19 17:27:50 字數 1974 閱讀 3845

總結本書前11章內容要點

---------------------------------

(1)注意python 2.x和python 3.x在作業系統上的環境配置。 

(2)建議用昇華編輯器。

(1)變數名只能包含數字,字母和下劃線,要避免命名錯誤。

(2)title(),upper(),lower()的運用。

(3)print()表示空1行,print(「\ n」* 3)表示空4行。

(4)注意單引號和雙引號實際上一樣。

(5)刪除空白rstrip(),lstrip(),strip(),注意可以加引數。

(6)str()將非字串表示為字串。

(7)python之禪:匯入這個。

(8)注意python 2.x和python 3.x中浮點數的操作。

(1)list [0]索引從0開始。

(2)修改元素list [0] ='a'。

(4)刪除元素:del,pop()括號裡加索引值,remove。

(5)sort()與sorted()區別用法,注意reverse()。

(6)列舉(序列,數字)。

(1)列表中的xx:

(2)數值列表:範圍(1,5)中的值:#列印1至4與切片取的位置一致,前取後不取。

(3)遠組,元素不可改變。

(4)切片可以定義步長。

(1)if,if-else,if-elif-else語句。

(2)列表解析式[**式for variable量列表if條件]進行附加

(1)字典的定義。

(2)訪問鍵值對。

(3)刪除鍵值對:德爾。

(4)遍歷鍵值對:for key,use.items()中的值:

(5)遍歷鍵:for key in use():  或者  for key in use.keys():。

(6)遍歷值:for value in use.values():。

(7)注意巢狀的使用。

(1)input 的工作原理:name = input("please tell me that you love me:")。

(2)int() 將數字字元編委數值。

(3)求模運算子:%。

(4)while 迴圈,使用標誌,break退出迴圈,continue的跳轉,避免無限迴圈。

(1)傳遞實參,注意返回值的確定。

(2)預設值。

(3)傳遞任意實數的實參:def fun(*para):。

(4)各種匯入,利用 as 設定別名。

(1)def __init__(self, name,age):self.name=name self.age=age  乙個指向例項本身的引用。

(2)繼承 class electricar(car): def __init__(self, make,model): super().__init__(make,model,year)   super()超類,父類。

(3)各種匯入。

(4)模組 collections 中的乙個類 ordereddict 記錄了鍵值對的新增順序。

(1)with open('.txt','r')as file: 自動關閉。

(2)lines = sentence.readlines() 儲存在乙個列表中。

(3)msg.replace('a','b') 將msg中的『a』變為『b』。

(4)try-except **塊。

(5)split() 建立單詞列表,預設空格分開。

(6)s.count('a')  s列表中記錄『a』出現的次數。

(7)模組 json 用於轉存。

(8)重構:改進**,變為函式解決實際問題。

(1)unittest模組用於測試。

(2)函式的測試:class namestestcase(unites.testcase):.

(3)類的測試:注意setup(self)的使用。

(4)assertequal('a','b')等斷言的運用。

Python 程式設計 從入門到實踐

1.官網安裝 3.環境配置 務必選中核取方塊add python to path 4.檢視 啟動python版本的命令 python 執行 print hello python world 5.終端執行x.py檔案 python x.py 7.檢視當前目錄中的所有檔案的命令 dir windows系...

Python程式設計從入門到實踐 基礎入門

python程式設計從入門到實踐 基礎入門 1 python中的變數 2 python首字母大寫使用title 方法,全部大寫upper 方法,全部小寫lower 方法 3 python中字串拼接使用 號 4 python中刪除字串的空格 刪除末尾空格的rstrip 刪除開頭空格的lstrip 刪除...

Python程式設計 從入門到實踐 1

內容總結自 python程式設計 從入門到實踐 安裝python3 安裝文字編輯器sublime text並配置python3環境 安裝sublime text tools new build system 將 untitled.sublime build 文件中的所有內容刪除,輸入以下內容 注意,...