1.利用key排序 d = {'d1':2, 'd2':4, 'd4':1,'d3':3,} for k in sorted(d): print(k,d[k]) d1 2d2 4d3 3d4 1 2.利用value排序:__getitem__ d = {'d1':2, 'd2':4, 'd4':1,'d3':3,} for k in sorted(d,key=d.__getitem__): print(k,d[k]) d4 1d1 2d3 3d2 4 反序:reverse=True d = {'
and 当俩个条件都满足时为True否为False or 任意一个条件满足时为True否为Flase not in 通常用于If语句,用来判断一个元素是否不在某个列表中 banned_user = ['andrew','carolina','david'] user = 'marie' if user not in banned_user: print(user.title()+',you can post a response if you wish.') If elif else 组合使用
# the example_1 aim to tell how to use dctionary,and how to access list or dictionary infos={"first_name":"jack","last_name":"mole","age":20,"city":"lendon"} for info in infos: print(st