l = [1, 5, -10, 0, 30, 22]
# 绝对值
print(abs(-5)) #5
#最大值
print(max(l)) #30
#最小值
print(min(l)) #-10
#长度
print(len('abc')) #3
print(len(l)) #6
# 返回除法整数及取余
print(divmod(10, 3)) #(3, 1)
# 开方
print(pow(2, 3)) #8
# 四舍五入
print(round(3.5)) #4
# 测试对象是否可以调用
print(callable(max)) #True
#print(callable(aaa)) #NameError: name 'aaa' is not defined
# 判断对象类型
print(type(l) == type([])) #True
print(isinstance(l, list)) #True
print(isinstance(l, int)) #False
# 列表类型转成元组
print(tuple(l)) #(1, 5, -10, 0, 30, 22)
#转成int
print(int('123')) #123
#print(int('123a')) #报错
#转成字符
print(type(str(123))) #<class 'str'>
str = 'hello world'
# 字符替换
print(str.replace('hello', 'hehe')) #hehe world
# 切割
print('a,b,c,d,e'.split(',')) #['a', 'b', 'c', 'd', 'e']
# 第一个字母大写
print(str.capitalize()) #Hello world
# 过滤
l = {0, 1, 2 , 3, 4, 5, 6, 7, 8, 9}
def f(x):
# 可以被2整除的数
if x%2==0:
return True
for x in filter(f,l):
print(x)
#0
#2
#4
#6
#8
name = ['张三', '李四', '王五']
age = [20, 22, 25]
tel = ['111111', '222222222', '333333333333']
sex = ['男', '女'] # 这里只有两个值
#合并
for x in zip(name, age, tel, sex):
print(x)
#['张三', 20, '111111', '男']
#['李四', 22, '222222222', '女']
# sex只有两个元素,所以第三个值就不出了了