python 日常一記 基礎

來源:互聯網
上載者:User

標籤:append   ==   去重   pre   err   訪問   app   key   ror   

# 添加字典

# d = {
#
# 95: ‘Adam‘,
#
# 85: ‘Lisa‘,
#
# 59: ‘Bart‘
#
# }
# # d[55]=‘jack‘
# print (d[95])

# 擷取key 合值
# d = {
# ‘Adam‘: 95,
# ‘Lisa‘: 85,
# ‘Bart‘: 59
# }
# for key in d:
# print (key+ ‘:‘,d[key])
# 判斷是否存在
# s = set([‘Adam‘, ‘Lisa‘, ‘Bart‘, ‘Paul‘])
# x=‘jack‘
# if x in s :
# print(‘測試‘)
# else:
# print(‘錯誤‘)
# 顯示變數和值

# s = set([(‘Adam‘, 95), (‘Lisa‘, 85), (‘Bart‘, 59)])
# for x in s:
# print (x[0],‘:‘,x[1])
# # print (x)
# 對比set進行訪問
# s = set([‘Adam‘, ‘Lisa‘, ‘Paul‘])
# L = [‘Adam‘, ‘Lisa‘, ‘Bart‘, ‘Paul‘]
# for a in L:
# if a in s:
# s.remove(a)
# else:
# s.add(a)
# print (s)
# 添加列表
# L = [‘Adam‘, ‘Lisa‘, ‘Bart‘]
# print(L[1])
# # L.append(‘JACK‘)
# L.insert(1,‘JACK‘)
# print (L)
# # 其他清單
# L = [‘Adam‘, ‘Lisa‘, ‘Bart‘]
# L[1]=‘JACK‘
# print (L)
# 添加字典
# d = {
# ‘Adam‘: 95,
# ‘Lisa‘: 85,
# ‘Bart‘: 59
# }
# d.update({‘jack‘:75})
# print(d)
d = {
‘Adam‘: 95,
‘Lisa‘: 85,
‘Bart‘: 59
}
# print (d.get(‘Adam‘))
# b=(d.get(‘Lsa‘))
# print(b)
# print(b)
a=‘Adam‘or ‘Bart‘
# if ‘Bart‘ in d:
# if a in d:
if a in d:
# print (d[‘Bart‘])
print (a,‘:‘,d[a])
else:
print (‘Error‘)
# 兩個列表長度對比
# s = [‘Adam‘, ‘Lisa‘, ‘Paul‘]
# L = [‘Adam‘, ‘Lisa‘, ‘Bart‘]
# a=len(s)
# b=len(L)
# print (a,b)
# # for a in L:
# if a == b:
# print (‘pass‘)
# else:
# print(‘error‘)
# 去重
# 方法1
# a = [‘Adam‘, ‘Lisa‘, ‘Paul‘,‘Adam‘,‘Adam‘,‘Lisa‘]
# b=[]
# for x in a:
# if x not in b:
# b.append(x)
# print (b)
# 方法2
# a = [‘Adam‘, ‘Lisa‘, ‘Paul‘,‘Adam‘,‘Adam‘,‘Lisa‘]
# a=list(set(a))
# print(a)
# 判斷x是否在a列表中
# a=[‘Paul‘, ‘Lisa‘, ‘Adam‘]
# x=‘Adam‘ and ‘Lisa‘ and ‘Paul‘
# if x in a:
# print (‘PASS‘)
# else:
# print (‘error‘)

python 日常一記 基礎

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.