字符串:各种奇葩内置--2017/9/3--2

字符串和元组很像

str1='abcd'
str1[:1]
'ab'

str1[1]
‘b’
字符串不能更改

str2=’biubiu’
capitalize 首字母大写
str2.capitalize()
‘Biubiu’

casefold 全部小写
str2.casefold()
biubiu
capitalize casefold 得到新字符串,strt2不变

count(start[,start[,end) 出现次数
str2.count(xi)
endswith 解释是否为xx
str2.endswith(xi)
startswith 开始是否为xx

expendtabs \t加空格,默认8(a个空格,8-a个空格)
str2.expendtabs(‘B\tiubi\tu’)
‘B iubi u’

find xx是否在字符串中,有-返回索引值,无-返回-1
rfind 右边找

index 与find一致,只是无返回异常
rindex

isalnum >1个字符并且所有均为数字或字符,T

isdigit all数字,T

islower all小写,T
isupper all大写,T

isnumeric all数字字符,T

isspace all空格,T

title 标题化(首字母大写,后面全小写)
istitle 首字母大写,后面全小写,T

join(sub)
str2=’biubiu’
str2.jion(123)
‘1biubiu2biubiu3’
123被隔开

ijust 左对齐

lower 大写变小写
upper

strip 首尾去掉,默认为空格
istrip 去掉左边所有空格
rstrip 右边

partition 找到sub,分成三个字符
str2=’biubiu’
str2.partition(‘iu’)
(‘b’,’iu’,’biu’)
rpartition

replace(old,new[,count) count 最多可替换数

split(sub) 找到sub就切,变成列表;默认为空格

splitlines \n为分隔

swapcase 大小写转换

translate()
str2=’biubiu’
str2.translate(str.maketrans(‘b’,’w’))
‘wiuwiu’

zfill 右对齐,前面用0填充

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值