笨辦法 學python 習題22(

2021-09-26 03:09:54 字數 607 閱讀 2805

字元或編碼

功能from sys import ar**

從sys模組種匯入ar**這個引數包

script,first,second,third = ar**

對ar**引數包解包

open()

開啟檔案或指令碼

.read()

讀取文字。可以把結果賦給乙個變數

close

關閉檔案。跟編輯器中的」檔案「——」儲存「是乙個意思

readline

truncate

清空檔案,小心使用該命令

write(『stuff』)

將"stuff"寫入檔案

seek(0)

將讀寫位置移動到檔案開頭

exists()

將文字名字串作為引數,檔案存在則返回true,否則返回false

len()

計算字串的長度

echo

建立檔案。例:echo 「this is a test file.」 > test.txt

cat顯示檔案。例:cat test.txt

def 函式名字(引數):

建立函式(如果是引數包,需要解包,是變數就可以直接用)

《笨辦法學python》習題38 40

mystuff 然後作者又給出了乙個錯誤的情況 class thing object def test hi print hia thing a.test hello 錯誤原因是test 只可以接受乙個引數,卻給了兩個。也就是 a.test hello 實際上是test a,hello 從這裡開始到...

《笨辦法學Python》 習題3

加分習題 系統 mac os 10.14 python 2.7.10 版本 笨辦法學python 第四版 print i will now count my chickens print hens 25 30 6.0 print roosters 100 25 3 4 print now i wil...

《笨辦法學Python》 習題6

加分習題 系統 mac os 10.14 python 2.7.10 版本 笨辦法學python 第四版 x there are d types of people.10 binary binary do not don t y those who know s and those who s.bi...