我有一个字符串“一切都好”,我想找到一个以"Eve“开头,以"ing”结尾的字符串,中间的字母可以是任何字母。我怎么才能在蟒蛇身上做到呢?
发布于 2022-11-02 05:43:21
假设这是你的字符串
my_string = "Everything is fine"您可以执行以下操作
my_string.split(" ")
for word in my_string.split(" "):
if word[:3] == "Eve" and word[-3:] == "ing":
print(word)
else:
pass此外,您还可以在这样的列表中分配所有这些单词。
my_words = []
my_string.split(" ")
for word in my_string.split(" "):
if word[:3] == "Eve" and word[-3:] == "ing":
my_words.append(word)
else:
passhttps://stackoverflow.com/questions/74284605
复制相似问题