s = "Amy love wang xiaojing"
s1 = "xiaojing"
# 返回第一次发现这个字符串的位置
s.find(s1)
# 返回-1表示没有找到
s2 = "Wanwan"
s.find(s2)
out:-1
s.inxde(s2)
out: ValueError: substring not found
# 使用的时候还可以使用区间
s = "Amy love wang xiaojing and \
zhang xiaojing"
s1 = "xiaojing"
#从下表20开始查找,看能否找到
s.find(s1,25)
out: 37
s = "一二三四五六七八九十"
print(s.isdigit())
print(s.isnumeric())
print(s.isdecimal())
out:
False
True
False
a = "liu dana"
b = "xiao jing"
s = "liu dana really love wang xiao jing"
print(s.startswith(a))
print(s.endswith(b))
c = "AAAAmy love xiaojing "
# 是否成功删除两边的空格不能观察出来
print(c.strip())
print()
print(c.strip(), end="------")
print("-----")
print(c.strip("A"))
print()
print(c.strip("A"), end="------")
out:
AAAAmy love xiaojing
AAAAmy love xiaojing-----------
my love xiaojing
my love xiaojing ------
s1 = "¥"
s2 = "_"
s3 = " "
ss = ["Amy", "love", "xiaojing"]
print(s1.join(ss))
print(s2.join(ss))
print(s3.join(ss))
out:
Amy¥love¥xiaojing
Amy_love_xiaojing
Amy love xiaojing