Python基础数据类型
定义:
int => 数字类型
str => 字符串数据类型
bool =>布尔值,True False
list 列表,用来存放大量数据 [] 表示,里面可以存放大各种数据类型
tuple 元祖,只读列表,不可进行修改等
dict 字典 {key:value}
set 集合,可以去除重复部分
实际操作:
replace 替换
s = "hello word python"
s1 = s.replace('hello','hi') #将 hello 转换成 hi
s2 = s.replace('hello','hi','2') #将 hello 转换成 hi,替换为2次
upper 大写
s3 = s.upper()
print(s3) #将 hello word python 全部转换成大写
stript() 去掉空白
s4 = s.strip()
print(s4) # 去掉 hello word python 两边的空格 切记:字符串中间空格去不了
s5 = s.leftstrip(‘hello word python’)# 去掉hello word python左边的空格
s6 = s.rightstrip(‘hello word python’) #去掉hello word python右边的空格
split() 切割. 返回列表. 用多长的刀. 就要损失掉多少
# s = "伊丽莎白鼠的溜肥肠还有挖掘机"
# 切片 [起始位置: 结束位置] 1.顾头不顾尾, 2.从左往右切
# print(s[1:3]) # 从1切到3. 但是取不到3 [1,3)
# print(s[1:]) # 从1开始切. 切到结尾
# print(s[:2]) # 从头切到2
# print(s[:]) # 从头到尾
# print(s[-3:-1]) # 只能从左往右切
# 给出第三个参数来控制方向,第三个参数叫步长
# print(s[-1:-3:-1]) # - 表示反方向. 从右往左切 输出结果 : 机掘
startswith() 判断是否以xxx开头