【python】-字符串常用操作

jion()方法:

print('-'.join(['1','2','3'])) 输出字符串1-2-3

name='my name is pengliyuan'

print(name.ljust(50,'*'))

print(name.rjust(50,'*'))

print(name.center(10,'*'))

print(name.isupper())

大小写转换:

print(name.upper())

print('Alex '.lstrip())左右边

strip:

剥夺,剥去

去除空格和换行

print('           Alex '.strip())

p=str.maketrans('abcdef','123456')对应

print('abc'.translate(p))

replace()方法:

print('ADB'.replace('A','a')#找最右边值的下标

spli()分割:

splitlines()按换行符分割

swapcase()大写边小写,小写变大写

title()首字母大写

zfill(50)不够用0填充

原文地址:https://www.cnblogs.com/linalove/p/8434894.html