python-赫-day18
作者:互联网
# 可变参数
def func(name, *args, **kwargs):
print(name)
print(args)
print(kwargs)
func("eric", 1, 2, "haha", gender="男", addr='xixi')
def f(a,b,c):
pass
f(*(1,2, 3))
内置函数
from random import randint
ls = [randint(10, 100) for _ in range(10)]
# .sort list的方法 对list原地操作
# ls.sort()
# print(ls)
# sorted() 内置函数 返回新的排序对象 参数可以是迭代对象
print(sorted(ls, reverse=True))
print(ls)
复杂类型排序
stu_ls = [
{'name': '张三', 'age': 76, 'height': 1.89},
{'name': 'lisi', 'age': 23, 'height': 2.09},
{'name': 'wagwu', 'age': 44, 'height': 1.39},
{'name': 'zhaol', 'age': 34, 'height': 1.49},
{'name': '天气', 'age': 23, 'height': 1.79},
]
def sorted_by_age(d):
# return d['age']
return d['height']
print(sorted(stu_ls, key=sorted_by_age, reverse=True))
print(sorted(stu_ls, key=lambda x:x['age'], reverse=True))
stu_ls.sort(key=lambda x:x['age'], reverse=True)
print(stu_ls)
import string
from random import randint
data = {k:randint(10, 100) for k in string.ascii_uppercase[:10]}
print(data)
# 转换成列表
data = list(data.items())
print(data)
# 排序
# data.sort(key=lambda x:x[1], reverse=True)
# print(data)
print(sorted(data, key=lambda x: x[1], reverse=True))
print(all([11, 222,333]))
print(all([0, 222,333]))
print(all([True, True,True]))
print(all([True, True,False]))
print(any([11, 222,333]))
print(any([0, 222,333]))
print(any([0, 0,0]))
print(any([True, True,True]))
print(any([True, True,False]))
print(any([False, False,False]))
print(any("dada"))
print(any("0"))
print(any(""))
num = int(input())
print(sum([int(i) for i in str(num*2)]))
标签:python,day18,age,data,ls,print,True,any 来源: https://blog.csdn.net/qq_39276337/article/details/120815501