字符串方法汇总
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)