跳到主要內容

發表文章

目前顯示的是 12月, 2018的文章

[Coding] Python

comment:   single line: #   multiple line: ''' ... ''' encode: # -*- coding: utf-8 -*- math operation: 先乘除後加減 5**2: 5 的平方 5**0.5: 平方根 log(8, 2) => 3 Data type None 就是 C 的 null 變數型態不需宣告 only int, float, string string 'mystring' mychar = string[0] #mychar is still string type string[2:5] s[2] == 'a' s += "append string" array/linked-list/stack (implemented by array)  fruits = ['orange', 'apple', 'pear', 'banana', 'kiwi', 'apple', 'banana'] len(fruits) fruits.count('apple') => 2 fruits.index('banana') => 3 fruits.index('banana', 4) => 6 fruits.remove('banana') del fruits[-1] fruits.insert(3, 'grape') fruits.reverse() fruits.append('grape') fruits += ['orange', 'peach'] fruits.sort() fruits.pop() => 'banana' nD 2D array 取值是用 a[i][j],不是用 a[i, j],後者回傳的是 tupl...