python 简单的记载

来源:互联网 发布:淘宝代购家具是骗局 编辑:程序博客网 时间:2024/05/17 03:47

python的数据类型

() 元组   aa=(xxx,yy,zzz)

[]   list     bb= ['a','b','c','d','e']

{}  字典   cc={'name':'tom','age':18,'sex':'man'}



判断一个 list 是否为空

传统的方式:

if len(mylist):    # Do something with my listelse:    # The list is empty

由于一个空 list 本身等同于 False,所以可以直接:

if mylist:    # Do something with my listelse:    # The list is empty

判断字典是否有某一个key

if('age' in test4.keys()):print("test包含age")else:print("test不包含age")

原创粉丝点击