笔记:
字符格式化输出 占位符 数据运算: 数据类型的初识 1.数字 整数 int (integer) 整型 长整型 (在python3以上版本不区分了,统一都叫整型) 2.布尔值 只有两种状态 真 Ture 条件成立 假 False 条件不成立 3.字符串 salary.isdigit() #.就是调用属性 计算机中,一切皆未对象 时间万物,皆为对象,一切对象皆可分类 列表,元组 查 索引(下标),都是从0开始 切片 .count,查某个元素的出现次数 .index,根据内容找元素的对应的位置 "xuyaochadeneirong" in a 增加 a.append() 追加 加在最后面 a.insert(index ,“内容”)把内容增加到指定位置 a.extend 扩展 修改 a[index]="新的内容" a[index:end]=["a","b","c"] 删除 remave("内容") pop (index) del a [index] a.clear()清空 排序 reverse 把列表里面的内容全部倒序排列 sort 把列表的内容按顺ACSN码表顺序排列·包括字符 身份判断 type (a) is list 4.浮点型 5.循环 loop 有限循环 for i in range(10) 无线循环 6. continue 跳出循环 执行条件代码,继续下一下循环 break 跳出当前终止循环,不执行下一次的循环
排序:
# reverse 把列表里的顺序颠倒过来 a.reverse()#执行之前:['wuchao', 'xiugai', 'wuchao1', 'wuchao2', 'wuchao3', 'wahaha'] print(a) #执行之后:['wahaha', 'wuchao3', 'wuchao2', 'wuchao1', 'xiugai', 'wuchao'] #sort 对数值执行排序,从小到大 字符串就是按ASC码表排列: x = [4,3,5,8,6,9,7,1,2] x.sort() print(x) #[1, 2, 3, 4, 5, 6, 7, 8, 9] x.reverse() print(x)#[9, 8, 7, 6, 5, 4, 3, 2, 1] a.sort()#['wahaha', 'wuchao3', 'wuchao2', 'wuchao1', 'xiugai', 'wuchao'] print(a)#['wahaha', 'wuchao', 'wuchao1', 'wuchao2', 'wuchao3', 'xiugai']