11.字符串相关操作



# 字符串
# 有序的字符集合
# 可切片
# 不可变,修改就是重新赋值
# a="hello "
a="hello"+"\n"
print(a)
print(r"hello"+"\n")
a="hello caona"
print(a.capitalize()) #第一个单词首字母大写
print(a.title()) # 每个都首字母大写
print(a.count("o"))
print(a.index("c"))
print(a.isupper())
print(a.islower())
print(a.isdigit())
print(a.upper())
print(a.endswith("a"))
print(a.startswith("h"))
print(a.replace("l","*"))
print(a.casefold())
print(a.center(20,"*"))
print(a.find("e"))
print(a.index("e"))
a1="{} is sb ,age is {}"
print(a1.format("caona",12))
a1="{name} is sb ,age is {age}"
print(a1.format(name="caona",age=18))
print(" ".isspace())
b=["1","2","3"]
print("_".join(b))
print(a.ljust(20,"*"))
print(a.rjust(20,"*"))
c=" df \n \t "
print(c)
print(c.strip())
print(c.rstrip())
print(c.lstrip())
d="my socre is 100,i want 110"
print(d.replace("100","1000"))
d="my socre is 100,i want 100"
print(d.replace("100","88",2))
print(a.split(" "))
print(a.rsplit())
print(a.swapcase())#大变小,小变大
print(a.zfill(30))# 长度30,不够0来凑


转载于:https://www.cnblogs.com/xh716/p/11551615.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值