python-赫-day18
2021/10/17 22:09:42
本文主要是介绍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的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门
- 2024-11-14Python编程入门指南
- 2024-11-13Python基础教程
- 2024-11-12Python编程基础指南
- 2024-11-12Python基础编程教程
- 2024-11-08Python编程基础与实践示例
- 2024-11-07Python编程基础指南
- 2024-11-06Python编程基础入门指南
- 2024-11-06怎么使用python 计算两个GPS的距离功能-icode9专业技术文章分享