python:特殊知识点
2页1、第8关:些新的知识点1、控制换和不换参数end= :实现print打印输出不换;print():实现换for i in range(1,3):print(%d X %d = %d % (i,2,i*2),end = ) #不换print() #来换for i in range(1,4):print(%d X %d = %d % (i,3,i*3),end = )print() #来换#输出结果1 X 2 = 2 2 X 2 = 41 X 3 = 3 2 X 3 = 6 3 X 3 = 9end= 也可控制结尾字符和间隔print(hello,end=) print(world) 输出结果: helloworldprint(hello,end= )print(world)输出结果: hello worldprint(hello,end=!)print(world)输出结果:hello!world2、列表的合并和排序列表合并的两种法:1 splat操作符 “*”连接列表; 2 使“+”号作为列表的连接符:list1 = 91, 95, 97, 99list2 = 92, 93, 96, 9
2、8list3 = *list1,*list2 或 list3 = list1+list2print(list3)#输出结果:91, 95, 97, 99, 92, 93, 96, 98两种法的区别:“+”只能连接列表,不能连接int型的数字,“*”可以灵活添加元素list3 = *list1,78,*list2 或 list3 = *list1,明,*list2列表排序的两种法:1 sorted(list) ; 2 list.sort() sorted(list) 返回个对象,可以作表达式。原来的 list 不变,成个新的排好序的 list 对象。list.sort() 没有返回值,直接改变原有的 listsorted(list3) list3.sort() 3 反向排序(由到):list3.sort(reverse=True) 3、计算列表平均值:numpy库.mean(list)import numpy as np # 导 numpy库,下出现的 np 即 numpy库scores1 = 91, 95, 97, 99, 92, 93, 96, 98scores2 = # 空列表,后会来放置符合条件的数average = np.mean(scores1) print(平均成绩是:.format(average) # 输出结果:平均成绩是:95.125for score in scores1: # 遍历score1列表中的数if score average: # 把score1列表中的数与average平均数做对scores2.append(score) # 少于平均分的成绩放到新建的空列表中print(低于平均成绩的有:.format(scores2) # 输出结果:低于平均成绩的有:91, 95, 92, 934、列表求和:sum()sum(1,2,3)的结果是6sum(2, 3, 4), 1)的结果是10,表示元组求和后再加上1.sum(0,1,2,3,4, 2)的结果是12,表示列表求和后再加上2.
《python:特殊知识点》由会员M****分享,可在线阅读,更多相关《python:特殊知识点》请在金锄头文库上搜索。
python:debug及代码书写规范
python基础知识:类的定制与继承
第13关:类的继承和定制
python基础语法合集
Python基础语法:类的使用
python:for循环和while循环
python基础知识:类与对象
python:定义函数
python:类和对象
python常见报错合集
python:调用模块及格式符数据拼接
[2019]超级企鹅篮球赛
建国70周年体育特别策划
python:用数据做判断:布尔值
python:列表和字典
python:文件读写
python:模块
python:容易遗忘的知识
尼尔森-体育产业生态圈《世界足球报告》
python:特殊知识点
2023-09-09 59页
2023-08-28 1页
2023-08-27 18页
2023-08-27 7页
2023-08-27 6页
2023-08-27 6页
2023-08-27 8页
2023-08-23 6页
2023-08-23 3页
2023-08-23 20页