一、简介
1.高级数据类型的公共方法:
列表元组字典或者字符串都能够共同使用的方法;
2.python的内置函数:
不需要使用import这种关键字导入任何模块就可以通过函数名直接调用的函数,eg:print函数;
3.python包含的内置函数:
1.len(item)计算容器中元素的个数;
2.del(item)删除变量;
3.max(item)返回容器中的最大值;
4.min(item)返回容器中最小的数;
5.cmp(item1,item2)比较两个值,-1小于/0相等/1大于(python3.x取消了cmp函数)//运算符:+,【1,2】+【3,4】–【1234】,合并;*,重复;in,元素是否存在;not in元素是否不存在;比较运算符,元素比较;
二、遍历字典的列表
students=[
{"name":"王小美",
"age":16,
"gender":True,
"height":1.987},
{"name":"钟离",
"age":17,
"gender":False}
]
find_name="钟离"
for stu_dic in students:
print(stu_dic)
if stu_dic["name"]==find_name:
print("找到了%s"%find_name)
#如果已经找到,应该直接退出循环,而不再遍历后续的元素
break
print("循环结束")
students=[
{"name":"王小美",
"age":16,
"gender":True,
"height":1.987},
{"name":"钟离",
"age":17,
"gender":False}
]
find_name="王小美"
for stu_dic in students:
print(stu_dic)
if stu_dic["name"]==find_name:
print("找到了%s"%find_name)
#如果已经找到,应该直接退出循环,而不再遍历后续的元素
break
print("循环结束")