python 日常一记 基础

# 添加字典

# 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')
posted @ 2018-08-06 23:27  mahaining  阅读(208)  评论(0编辑  收藏  举报