2.1 Data types
2.2 String
2.3 List operation
2.1 Data types
# Ptyhon运算符‘‘‘数字运算符: + - * / %关系运算符: a == b a>b a<b a!=b >= <=赋值运算符: a = b += -= *= /=逻辑运算符: and or not‘‘‘## 整型(int)a = 10print(a)## 布尔型(bool) True(真) Falle(假)## 浮点型(float): 小数类型a = 1.2345print(a)## 字符串(str)string = ‘abc‘print(string)
2.2 String
string = ‘abcdefg aa bbd ‘## 字符串操作## find: 查找内容所在字符串位置,顺序从0开始;-1表示查不到print(string.find(‘d‘))# 切片:[起始:结束:步长]print(string[0:])print(string[0:5])print(string[0:5:2])# replace (需要替换字符,替换后字符,替换次数)print(string.replace(‘a‘, ‘A‘))print(string.replace(‘a‘, ‘A‘, 2))# split 分隔符(分隔标志,分隔次数)print(string.split())print(string.split(‘ ‘, 1))# strip 去字符串两端的空白字符print(string.strip())# title 首字母大写print(string.title())
2.3 List operation
# append: 添加元素lt = [1, 2, 3, ‘a‘, ‘b‘, ‘c‘]lt.append(‘d‘)print(lt)# insert: 指定位置插入指定元素lt = [1, 2, 3, ‘a‘, ‘b‘, ‘c‘]lt.insert(2, ‘%‘)print(lt)# pop: 按下标弹出元素lt = [1, 2, 3, ‘a‘, ‘b‘, ‘c‘]print(lt.pop()) # 默认从最后弹起print(lt)lt = [1, 2, 3, ‘a‘, ‘b‘, ‘c‘]print(lt.pop(2))print(lt)# remove: 删除元素lt = [1, 2, 3, ‘a‘, ‘b‘, ‘c‘]lt.remove(‘a‘)print(lt)# index: 查询指定元素的下标lt = [1, 2, 3, ‘a‘, ‘b‘, ‘c‘]print(lt.index(3))# sort 顺序排序lt = [1, 2, 3]lt.sort()print(lt)# reverse 倒序排序lt = [1, 2, 3]lt.reverse()print(lt)
January 19 "Basic knowledge of Python3"