2022-08-25 学习Python-Day8
字符串看了两天功能真的太多了,f字符串觉得比formate更加直观{:10_256:}############################P31
x='www.ilovefishc.com.cn'
xp=x.partition('.')
print(xp)
xp = x.rpartition('.')
print(xp)
str='苟日新,日日新,又日新'
str_s=str.split(',')
print(str_s)
str_s=str.rsplit(',')
print(str_s)
str_s=str.split(',',1)
print(str_s)
str_s=str.rsplit(',',1)
print(str_s)
str='苟日新\n日日新\n又日新'
str_s=str.splitlines(True)
print(str_s)
s='.'.join(['www','ilovefishc','com'])
print(s)
s=''.join('ilovefishc'*3)
print(s)
############################P32
year='2010'
year_str='工作室成立于{}年'.format(year)
print(year_str)
str='1+2={},2的平方{},3的立方{}'.format(1+2,2*2,3*3*3)
print(str)
str='{1}看到{0}就很激动'.format('我','美女')
print(str)
str='{0}{0}{0}{1}{1}{1}{1}'.format('是','非')
print(str)
str='我叫{name},我爱{fav}'.format(name='我',fav='小姐姐')
print(str)
str='我叫{name},我爱{0},喜爱{0},运气都不喜欢太差'.format('python',name='小甲鱼')
print(str)
str='{},{},{}'.format('是','{}','非')
print(str)
str='{:^10}'.format('250')
print(str)
str='{1:>10}{0:<10}'.format('520','250')
print(str)
str='{left:>10}{right:<10}'.format(left='520',right='250')
print(str)
str='{:010}'.format(250)
print(str)
############################P33
str='{:+}{:-}'.format(520,-250)
print(str)
str='{:,}'.format(1234)
print(str)
str='{:,}'.format(123456789)
print(str)
str='{:.2f}'.format(3.1415926)
print(str)
str='{:.2g}'.format(3.1415926)
print(str)
str='{:.6}'.format('aaasssddd')
print(str)
str='{:b}'.format(80)
print(str)
str='{:c}'.format(80)
print(str)
str='{:d}'.format(80)
print(str)
str='{:o}'.format(80)
print(str)
str='{:x}'.format(80)
print(str)
str='{:#x}'.format(80)
print(str)
str='{:e}'.format(80)
print(str)
str='{:E}'.format(80)
print(str)
str='{:f}'.format(3.141)
print(str)
str='{:g}'.format(1234.56789)
print(str)
str='{:%}'.format(1234.56789)
print(str)
str='{:.2%}'.format(1234.56789)
print(str)
str='{:.{prec}f}'.format(1234.56789,prec=2)
print(str)
str='{:{fill}{align}{width}.{prec}{ty}}'.format(3.1415926,fill='+',
align='^',width=10,prec=3,ty='g')
print(str)
year='2010'
year_str=f'工作室成立于{year}年'
print(year_str)
num=f'{-520:010}'
print(num)
fill='+'
align='^'
width=10
prec=3
ty='g'
num=f'{3.1415:{fill}{align}{width}.{prec}{ty}}'
print(num)
页:
[1]