原创 os.path 模塊

os.path.abspath(path) #返回絕對路徑 os.path.basename(path) #返回文件名 os.path.common

原创 exercise 10

print "I am 6'2\" tall." \" to mean" in case mistake with ending print 'I am 6\'2" tall.' tabby_cat="\t I'm tabbed i

原创 exercise11

print"How old are you?",   #print 後面逗號表示 在屏幕顯示的時候 鍵入在同一行,如果沒有逗號 鍵入會新起一行age = raw_input()print"How tall are you?",heig

原创 exercise18 命名 變量 代碼 函數

函數做3件事: 他們給代碼命名,就像給字符串和數字賦給一個變量名。他們接收參數,就像腳本中的argv。使用第一和第二條實現你自己的迷你腳本或者小型方法。 # this one is like your scripts with arg

原创 exercise 20 函數和文件

from sys import argv script, input_file = argv def print_all(f):     print f.read() def rewind(f):     f.seek(0)      

原创 exercise 34 訪問列表中的元素

animals = ['bear', 'python', 'peacock', 'kangaroo', 'whale', 'platypus'] The animal at 1.      pythonThe 3rd animal.   

原创 ex44 繼承還是組成

繼承的使用原則: 我們要儘量簡單的使用繼承,或者用組成代替繼承,而且做好不要使用多繼承。 父類和子類有三個相互影響的方法: 子類的動作暗含(imply)了父類的動作子類的動作覆蓋(override)了相應的父類動作子類的動作改變(alt

原创 exercise 26 test

def break_words(stuff): """This function will break up words for us.""" words = stuff.split(' ') return wo

原创 exercise 43 基本的面向對象分析和設計

用python面向對象編程的過程(一般可以這麼用,不一定所有問題都是這個思路解決) 1.Write or draw about the problem. 寫下或畫出問題 2.Extract key concepts from 1 and

原创 exercise 36 設計和調試-作業待續

if語句的規則 1. if語句中必須要有else 2. 如果因爲else語句沒有任何意義,那麼可以在else裏面打印錯誤信息,並且停止程序。 3. 不要嵌套if語句超過兩層,最好是把裏面的if語句寫到另外的函數中。 4. 給if語句的前後

原创 exercise 42 繼承 包含 對象和類

is-a就是對象和類之間通過類的關係相關聯;繼承 has-a是對象和類相關聯是因爲他們彼此參考。包含 is-a是三文魚和魚的關係;has-a是三文魚和鰓的關係 總結: 記住!!一個新的頂級類必須繼承object super(Empl

原创 exercise 37 符號複習-待續

Keywords Keyword Description Example and Logical and. True and False == False as Part of the with-as statement. with X

原创 鍵盤輸入監聽

Python鍵盤輸入和鼠標操作 鍵位碼錶: 字母和數字鍵     數字小鍵盤的鍵       功能鍵         其它鍵        鍵   鍵碼     鍵   鍵碼       鍵   鍵碼     鍵      鍵碼   

原创 exercise 38 列表操作

ten_things="Apples Orange Crows Telephone Light Sugar" # no comma between two words print "Wait there are not 10 thin

原创 exercise 39 字典

簡單介紹: list的使用: >>> things = ['a', 'b', 'c', 'd'] >>> print things[1] b >>> things[1] = 'z' >>> print things[1] z >>> th