物件操作

List

#Insert 
aList = [123, 'xyz', 'zara', 'abc']
aList.insert( 3, 2009)
print "Final List : ", aList

#Reverse
aList.reverse()

#去除重複
newList = list(set(aList))

# 刪除
li = [1,2,3,4,5,6]
# 删除對應索引的元素
del li[2]
# li = [1,2,4,5,6]

# 删除最后一个元素
li.pop()
# li = [1,2,4,5]

# 刪除list中指定位址的內容並指定到新的變數中
a = li.pop(0)
# li = [2,4,5]

# 删除指定值的元素
li.remove(4)
# li = [2,5]

參考連結: https://www.tutorialspoint.com/python/list_insert.htm https://www.douban.com/note/277146395/

判斷a list內容是否都出現在b list中: http://thispointer.com/python-check-if-a-list-contains-all-the-elements-of-another-list/

排序

參考連結: http://www.iplaypy.com/jinjie/jj114.html

Dict

遍歷

列出所字典內容,.keys()、.values()、dict.keys()、.items()

刪除

指定key並刪除

參考資料: https://blog.csdn.net/mmc2015/article/details/50777349

排序

https://segmentfault.com/a/1190000004959880

判斷

判斷型態

判斷數字 http://www.runoob.com/python/att-string-isdigit.html http://www.runoob.com/python3/python3-string-isnumeric.html

判斷數字

https://www.itread01.com/article/1533266784.html

https://blog.mimvp.com/article/25955.html

is vs ==

http://www.iplaypy.com/jinjie/is.html

http://blog.blackwhite.tw/2013/05/python-is.html

Class

https://marco79423.net/articles/淺談-python-的屬性/

https://medium.com/@weilihmen/關於python的類別-class-基本篇-5468812c58f2

Copy

http://www.runoob.com/w3cnote/python-understanding-dict-copy-shallow-or-deep.html

sort

http://blog.51cto.com/wangwei007/1100742

string insert方式

https://stackoverflow.com/questions/5254445/add-string-in-a-certain-position-in-python

Last updated

Was this helpful?