1. String類型輸出,看樣本x = "There are %d types of people" % 10binary = "binary"do_not = "don't"y = "Those who know %s and those who %s" % (binary, do_not)z = "Those who know %r and those who %r" % (binary, do_not)print xprint yprint zprint "I said: %r." %
1. 檔案寫操作檔案寫操作,需要在開啟檔案的時候添加參數,如open("filename", "w")以下是對檔案操作的函數小結close -- Closes the file. Like File->Save.. in your editor.read -- Reads the contents of the file, you can assign the result to a variable.readline -- Reads just one line of a text
這個系列的部落格是學習《Learn Python the Hard Way》中做的筆記。1. 由於今天需要看的five chapters是複習性質的內容,把前邊的內容綜合了一下,所以沒有新內容只把代碼貼在這View Code print "Let's practice everything."print "You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs."poem = """\t The
1. list相關的有一個比較有趣的問題,就是mystuff.append('hello'),python是怎麼解釋的。這裡有段話講的比較清楚,就不翻譯了,直接貼過來。Python sees you mentioned mystuff and looks up that variable. It might have to look backwards to see if you created with =, look and see if it is a function argument,
1. 今天學了一些概念。(書的第41~43章)用這個方法可以分清楚class、object、instance## Animal is-a object (yes, sort of confusing) look at the extra creditclass Animal(object): pass## Dog is-a animal, it has-a nameclass Dog(Animal): def __init__(self, name): ## ??
1. list比較熟悉了,但是list的函數們還不清楚,參考http://docs.python.org/2/tutorial/datastructures.html2. for和while經驗是盡量少用while,因為while出錯的機會大。3. 綜合起來寫的一個小程式from sys import exitdef gold_room(): print "This room is full of gold. How much do you take?" next =