内置函数
判断属于或者不属于 in / not in
字符串、字典、列表、元组、集合: 里面有多个元素组成的数据
可迭代的数据对象 (字符串、字典、列表、元组、集合)
a = 'helloworld'
判断 字符 x 在不在 a中
res = 'x' in a
print(res)
res = 'x' not in a
print(res)
b = {3,4,5,6,7}
判断5 在不在 b中
res = 5 in b
print(res)
c = {'张三': 110, "李四": 119, '王五': 120}
res = '张三' in c # 字典的判断,通过 key 键 去判断
print(res)
len() 获取 可迭代的数据对象中 有多少个元素a = 'xyz'
b = [1,2,3,4,5]
c = (1,2,3,4,5)
d = {1,2,3,4,5}
e = {'张三': 110, "李四": 119, '王五': 120}
print(len(a))
print(len(b))
print(len(c))
print(len(d))
print(len(e))
max() min() # 从可迭代的数据对象中,获取最大值/最小值
a = 'axyz'
print(max(a)) # a-z
print(min(a))
b = [1,2,3,4,5]
print(max(b))
print(min(b))
c = (1,2,3,4,5)
print(max(c))
print(min(c))
d = {1,2,3,4,5}
print(max(d))
print(min(d))
e = {8: 110, 9: 119, 10: 120}
print(max(e)) # 如果字典使用 max min 比较只针对于 key
print(min(e))

浙公网安备 33010602011771号