python中字符串的常用操作

"""
字符串常用的操作
"""
name = "alexxxx li"
# 将首字母转换为大写,但实际的name变量没有变
print(name.capitalize())
print(name)
#大写全部变为小写
print(name.casefold())
print(name.center(50,'-'))
print(name.count("x"))
print(name.endswith("Li"))
#在字符串中找字母e 找到返回index 找不到则返回-1
print(name.find("e"))

猜你喜欢

转载自blog.csdn.net/kokodudu/article/details/81505277