1.数据类型
int 1,2,3用于计算
bool True,False用于判断
str 存储少量数据,用于操作
list 存储大量数据 [1,2,3,'asd',[5,'fdg']]
元祖 只读 (1,2,3,’第三方’,)
dict 字典 {‘name’:'张三',‘age’:18}
集合 {1,22,33,‘dfg’}
int bit_length()
#int ----> str
i = 1
s = str(i)
#str ---> int
s = '123'
i = int(s)
#int ----->bool 只要是0 ----》False 非0就是True
i = 3
b = bool(i)
print(b)
#bool----> int
#True 1
#False 0
#str --->bool
#s = "" -----> False
#非空字符串都是True
#s = "0" -----> True
# split str ---->list
# s = ';alex;wusir;taibai'
# l = s.split('a')
# print(l)
2.字符串索引与切片
s = 'sadghjdf'
索引:
s1 = s[0]
s2 = s[-1]
切片: 顾头不顾尾
s5 = s[0:4]
s6 = s[0:-1]
s7 = s[:]
s8 = s[0:]
s[首:尾:步长]
s10 = s[0:5:2]
s11 = s[4:0:-1]
3.字符串操作
s = 'alexWUsir'
s1 = s.capitalize() # 首字母大写
s2 = s.upper() #全大写
s3 = s.lower() #全小写
s4 = s.swapcase() #大小写翻转
# 每个隔开(特殊字符或者数字)的单词首字母大写
s5 = s.title()
#居中,空白填充
# s = 'alexWUsir'
# s6 = s.center(20,'~')
# s = 'alex\tsir'
# s7 = s.expandtabs()
# s8 = 'alex二哥'
# #公共方法
# l = len(s8)
#以什么开头结尾 endswith
# s = 'alexWUsir'
# s7 =s.startswith('alex')
# s71 = s.startswith('e',2,5)
# find 通过元素找索引,找不到返回-1
# index通过元素找索引,找不到报错
# s = 'alexWUsir'
# s8 = s.find('A')
# s81 = s.index('A')
# print(s81,type(s8))
#strip rstrip lstrip
# strip 默认删除前后空格
# s = 'alexWUsir%'
# s9 = s.strip('%')
# print(s9)
# s = ' *a%lexWUsi* r%'
# s91 = s.strip(' %*')
# print(s91)
# s = 'alexaa wusirl'
# s10 = s.count('al')
# print(s10)