判断字符串开头和结尾,字符串的置换,字符串的大小写切换
作者:互联网
判断字符串是否以 XX 开头?得到一个布尔值
#endswith 判断字符串是否以 XX 结尾?得到一个布尔值
#v1 = input("please tell")
v1 = "我爱你"
result = v1.endswith("爱")
print(result)
#输出False
------------------------------------
##startsswith判断是否以XX开头,得到一个布尔值
v1 = "我爱你"
result = v1.startswith("我")
print(result)
#输出Turn
字符串的置换
#replace置换
count = input("请输入评论信息:")
count = count.replace("hello","12")#如果输入 hello,输出12
count = count.replace("hehe","wuuw")#输入hehe,输出wuuw
print(count)
#输入1,置换2
v1 = "高清.mp4"
new_v1 = v1.replace("mp4","avi")
new_v2 = new_v1.replace("高清","步兵")
print(new_v2)
字符串大小写的切换
#变为大写
v1 = "aaaaaaa"
v2 = v1.upper()
print(v2)
#变为小写
v1 = "AAAAA"
v2 = v1.lower()
print(v2)
标签:count,结尾,print,replace,v1,v2,大小写,字符串 来源: https://www.cnblogs.com/li-aolin/p/16543893.html