“””#Python四種型態增加元素
list.append(元素),
tuple1 = tuple + (元素, ),
set.add(元素),
dict[key]=value”””
lst = [1,2,3]
lst.append(4)
#list使用 .append(元素)
print(lst)
tp = (1,2,3)
tp1 = tp + (4, )
#tuple使用 + (4,),
#只加單一元素,後面還要逗點
print(tp1)
set1 = {1,2,3}
set1.add(4)
#set.add(元素)
print(set1)
dic = {“a”:1, “b”:2, “c”:3}
# “a”注意要” “,不然視為變數
dic[“d”]=4
#dict[key] = value
print(dic)
![Python四種型態增加元素 list.append(元素), tuple = tuple + (元素, ), set.add(元素), dict[key]=value - 儲蓄保險王](https://savingking.com.tw/wp-content/uploads/2022/05/20220513083711_22.png)
“””
用*2可以將tuple內的資料
多複製一份
不是將裡面的元素*2
“””
![Python四種型態增加元素 list.append(元素), tuple = tuple + (元素, ), set.add(元素), dict[key]=value - 儲蓄保險王](https://savingking.com.tw/wp-content/uploads/2022/05/20220513125956_9.png)
![Python:如何用pandas.concat() 合併兩個DataFrame並重置index? pd.concat([df1, df2]) .reset_index(drop=True) ; pd.concat([df1, df2], ignore_index=True) Python:如何用pandas.concat() 合併兩個DataFrame並重置index? pd.concat([df1, df2]) .reset_index(drop=True) ; pd.concat([df1, df2], ignore_index=True)](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2023/03/20230311123232_5.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

![Python TQC考題604 眾數, cnt[L.index(n)]+=1, L[cnt.index(max(cnt))], if L.count(n)>maxcnt: Python TQC考題604 眾數, cnt[L.index(n)]+=1, L[cnt.index(max(cnt))], if L.count(n)>maxcnt:](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2022/04/20220430181911_73.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

![Python: 字串 str.find(關鍵字[,start][,end]),找不到的話回傳-1,如何找出資料字串中,所有關鍵字的index?詞頻計算 Python: 字串 str.find(關鍵字[,start][,end]),找不到的話回傳-1,如何找出資料字串中,所有關鍵字的index?詞頻計算](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2022/11/20221122100657_32.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

![Python: Regular Expression 正規表示法 正則表達式 import re ; pattn = “[\d]{4}\/[01][\d]\/[0123][\d] [\d]{6}” ; match = re .search (pattn,text) .group() Python: Regular Expression 正規表示法 正則表達式 import re ; pattn = “[\d]{4}\/[01][\d]\/[0123][\d] [\d]{6}” ; match = re .search (pattn,text) .group()](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2022/09/20220901154435_19.png?quality=90&zoom=2&ssl=1&resize=350%2C233)



近期留言