2019年12月21日 星期六
2019年3月6日 星期三
Python各種內藏方法
# 初始化方法
def __init__(self):
# 直接呼叫, representation
def __repr__(self):
# 使用print會呼叫
def __str__(self):
# 迭代方法
def __iter__(self):
ex.
- for i in xrange(1000): pass
#返回迭代對象
2019年1月20日 星期日
Python List(set)跟 dict 新增跟刪除語法整理
r = []
n = 3
for i in range(n):
r.append(L[i])
另有extend用法(之後整理)
Python 字典(Dictionary) update()
函数把字典dict2的键/值对更新到dict里。
L[-2:]
output:: ['Bob', 'Jack']
L[-2:-1]
output:: ['Bob']
Map運算
list(map(lambda x: x**2, l))
訂閱:
意見 (Atom)