day1
数字类型和字符串类型
1.bin()函数将十进制转换成二进制
2.oct()函数将十进制转换成八进制
3.hex()函数将十进制转换成十六进制
十六进制表示:0-9 a b c d e f
4.数字类型的特性:
分类:整型,布尔,浮点,复数
5.字符串类型
引号包含的都是字符串类型
S1='hello world' s="hello world"
s2="""hello world"""
s3='''hello world'''
单引双引没有区别
6.字符串的常用操作 A.stip()
strip()移除空白,也可以去除其他的字符
len()长度 切片:如print(x[1:3])也是顾头不顾尾
print(x[0:5:2])#0 2 4
capitalize()首字母大写
center()居中显示例如:x='hello' print(x.center(30,'#'))
count():计数,顾头不顾尾,统计某个字符的个数,空格也算一个字符
endswith()以什么结尾
satrtswith()以什么开头
find()查找字符的索引位置,如果是负数,代表查找失败
format()字符串格式化
1.msg1='name:{},age:{},sex:{}'
print(msg1.format('摆渡舟',30,’男’))
2.msg2='name:{0},age:{1},sex:{0}'
print(msg2.format('nnn','mm'))
3.msg3='name:{x},age:{y,sex:{z}'
print(msg3.format(x='摆渡舟',y='30',z='男'))
isdigit()判断是否是数字
islower()判断是否是全部小写
isupper()判断是否是全部大写
lower()全部转换为小写
upper()全部转换为大写
isspace()判断是否是全都是空格
istitle()判断是否是标题(首字母大写)
swapcase()大小写字母翻转
join()连接
A.join(B)是在B的各元素后面加入A
repalce()替换
msg='hello alex'
print(msg.replace('e'),'A',1)
print(msg.replace('e'),'A',2)
ljust()左对齐
X='ABC' print(x.ljust(10,'#'))
rjust()右对齐
X='ABC' print(x.ljust(10,'*'))

浙公网安备 33010602011771号