Python学习第三天

本文介绍了Python中常用的字符串处理方法,包括expandtabs()、isdecimal()、isdigit()、isnumeric()等用于检查字符属性的方法,以及center()、ljust()、rjust()、zfill()等用于格式化字符串的方法。

expandtabs():  # \t为制表符,\n为换行。断句20

  test="1234567\t89"

  v=test.expandtabs(20)

  print(v,len(v))

 

isdecimal():  #当前输入的是不是数字

isdigit():  #当前输入的是不是数字

isnumeric():  #判断当前输入的是否是数字

  test="②"

  v1=test.isdecimal()

  v2=test.isdigit()

  print(v1,v2)

 

isidentifier():  #输入的是否是,字母、数字、下划线、标识符、def、class

islower():  #判断是否为小写

isspace():  #判断是否全部为空格

  test="      "

  v=test.isspace()

  print(v)

 

istitle():  #判断是不是标题

title():  #转换成标题

  test="Return True if all cased characters in S are uppercase and there is"

  v1=test.istitle()

  print(v1)

  v2=test.title()

  print(v2)

 

join():  #将字符中的每一个元素按照指定分隔符进行拼接

  test="nishifeng"

  print(test)

  v="  ".join(test)

  print(v)

 

center():  #字符串居中,在字符串中左右排列字符,共N位

  test="alex"

  v=test.cemter(11,"中")  

  print(v)

 

ljust():  #在字符串后面添加字符,加上字符串共N位

  v2=test.ljust(20,$)

  print(v2)

rjust():  #在字符串前面添加字符,加上字符串共N位

  v3=test.rjust(20,"#")

  print(v3)

zfil():  #字符串前面添加0,算上字符串共N位

  v4=test.zfill(20)

  print(v4)

 

 

 

 

转载于:https://www.cnblogs.com/libint/p/9431467.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值