python_3_字符串

1.strip,lstrip,rstrip

" hi, ming ".strip()   #去掉前后空格
"@hi,ming@".strip("@") #去掉@

2.大小写互换

# 1.lower()
# 2.upper()
# 3.swapcase() 大小写互换

3.左右填充

"sos".ljust(20,"#")
# 'sos#################'
"sos".rjust(20,"#")
"sos".center(20,"#"

4.查找

# “”.find(str)
# "".index()

5.分割,链接

# "".join(["1","2"])
# "".split(xx)

6.常用的字符串测试

"".startsWith()
"".endsWith()
"".isalpha()
"".isalnum()
"".isdigit()
"".isspace()
"".islower()
"".isupper()

 

 

 

 
 

你可能感兴趣的:(python_3_字符串)