python字符串方法

字符串方法汇总

add
class
contains
delattr
doc
eq
format
ge
getattribute
getitem
getnewargs
getslice
gt
hash
init
le
len
lt
mod
mul
ne
new
reduce
reduce_ex
repr
rmod
rmul
setattr
sizeof
str
subclasshook
_formatter_field_name_split
_formatter_parser
capitalize
center
count
decode
encode
endswith
expandtabs
find
format
index
isalnum
isalpha
isdigit
islower
isspace
istitle
isupper
join
ljust
lower
lstrip
partition
replace
rfind
rindex
rjust
rpartition
rsplit
rstrip
split
splitlines
startswith
strip
swapcase
title
translate
upper
zfill

###字符串定义
s = 'spam'

###字符串序列操作

#字符串长度
print(len(s))
#字符串索引
print(s[0])
print(s[1])
print(s[-1])
print(s[len(s)-1])
#字符串切片
print(s[:])
print(s[1:2])
print(s[:2])
print(s[len(s)-2:])
print(s+"8")

#字符串类型不可变
#s[0] = "p"错误
#but
s = 'z' + s[1:]
print(s)

#搜索
a = s.find("pa")
#替换
s = s.replace("pa",'ap')
print(a,s)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值