原创 Python入門的36個例子 之 18 -> Modules —— 將它們放到不同的文件裏
例1: # _018 # This is a module (if write Chinese in a module, there will be a error) def func1(): print 'This is f
原创 Python入門的36個例子 之 35 -> try – 一個使用的例子
源代碼下載:下載地址在這裏 # 039 while True: try: x = int(raw_input('Input a number:')) y = int(raw_input('In
原创 Python入門的36個例子 之 31 -> OOP – 屬於類的變量和屬於對象的變量
源代碼下載:下載地址在這裏 # 035 class Person: population = 0 #這個變量是屬於整個類的 def __init__(self, name): self.name =
原创 Python入門的36個例子 之 22 -> Sequences —— 統一的訪問方式以及負索引
源代碼下載:下載地址在這裏 # 025 # 序列的神奇之處在於你可以使用相同的方式tuple、list和string se = ['a', 'b', 'c', 'd'] li = ['a', 'b', 'c', 'd'] tu =
原创 Python入門的36個例子 之 19 -> Tuple(元素組)
源代碼下載:下載地址在這裏 # 023 # Tuple(元素組)是不可變的列表 tuple1 = (1, 2, 3) print tuple1 tuple2 = (tuple1, 4, 5, 6) # 一個元素組可以作爲另外一個元素
原创 Python入門的36個例子 之 23 -> Objects and References —— 複製引用還是複製實體對象
源代碼下載:下載地址在這裏 # 026 aList = ['1','2','3','4'] aListCopy = aList # 其實,這裏僅僅複製了一個引用 del aList[0] print aList print aLis
原创 Python入門的36個例子 之 32 -> OOP – Inheritance 繼承
源代碼下載:下載地址在這裏 A Byte Of Python 中關於繼承有這樣的文字: Suppose you want to write a program which has to keep track of the
原创 Python入門的36個例子 之 19 -> List
源代碼下載:下載地址在這裏 # 022 listNum1 = [1, 3] listNum2 = [2, 4] listStr1 = ['a', 'c'] listStr2 = ['b', 'd'] # 列表的合併 list1 =
原创 Python入門的36個例子 之 26 -> File In Console Out
源代碼下載:下載地址在這裏 # 029 aFile = file(r'C:/in.txt', 'r') while True: line = aFile.readline() if len(line) == 0
原创 Python入門的36個例子 之 27 -> Add Something Into A File
源代碼下載:下載地址在這裏 e.g.1 # 030 aFile = file(r'C:/temp.txt', 'a') aFile.write('又添加了一行。') aFile.close() output:
原创 Python入門的36個例子 之 21 -> Dictionary —— 通過你的ID找到你
源代碼下載:下載地址在這裏 # 024 dict1 = { '5064001':'Mememe', '5064002':'tutu', '5064003':'t
原创 Python入門的36個例子 之 24 -> 再說說String
# 027 toolName = 'Google' if toolName.startswith('Go'): print 'The tool/'s name starts with /"Go/".' if 'oo' in too
原创 Python入門的36個例子 之 30 -> OOP – 初始化
源代碼下載:下載地址在這裏 # 034 class Person: def __init__(self, name): self.name = name # 這一句中第一個name是類中包含的域,第二個nam
原创 Python入門的36個例子 之 33 -> try – 異常是不可避免的,關鍵是怎樣處理
源代碼下載:下載地址在這裏 # 037 fileName = '' while 1: fileName = raw_input("Input a file name:") if fileName == 'q':
原创 什麼情況下會失眠
<!-- @page { margin: 2cm } P { margin-bottom: 0.21cm } --> 什麼情況下會失眠 人在面臨壓力的時候會失眠,但是僅僅用壓力解釋失眠有些粗糙。我認爲用“創造性思維”來