python3 set集合,以及字典,提示,python3set

來源:互聯網
上載者:User

python3 set集合,以及字典,提示,python3set


#set集合,無序不可重複
setjh={'ofgh','gegds','uutytr'}

setjh.add('uuuuu')#添加單個元素
setjh.remove('ofgh')#刪掉單個元素
print(setjh)
#字典 鍵和值 建不可重複
zidian={'cn':"chain",'cn':'chh'}
print(len(zidian))#字典長度
print(zidian)
zidian.__setitem__('us','jhu')#添加元素
print(zidian)
#set集合使用
ry=input('請輸入任一字元:')
tongji={}
n=0
for s in ry:
tongji.get(s)
if n is None:
tongji.__setitem__(s,1)
else:
tongji.__setitem__(s,n+1)
print(tongji)
for key in tongji:
print('%s 出現了 %d次 '%(key,tongji.get(key)))

#取數到3後的數
ct=int(input('請輸入一個整數:'))
dui=[]

for num in range(1,ct+1):
dui.append(num)
while True:
if len(dui)==1:
break;
n=n+1
if n%3==0:
dui.pop(0)
else:
dui.append(dui.pop(0))
print(dui)

'''
函數;獨立調用,獨立定義
方法:依賴定義,依賴調用

'''
#回掉函數
def huidiao(data,r):
for a in data:
if r(a):
return a

def guize(b):
return b%3==0
print(huidiao([1,2,3,4,5,6,7,8,9],guize))

def daxiao(d,x):
if d<x:
d,x=x,d
return d,x
print(daxiao(1,6))



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.