mercredi 3 mars 2021

How to search variable for letter [duplicate]

import random

words = ["James", "Word", "Bodies"]

w = random.choice(words)

if w contains "a":
     print("Hello")

That last line is what I am trying to find. How do I search a string for a word or letter? The function

if w.startswith("a"):
     print("Hello.")

Does not suit what I need.




Aucun commentaire:

Enregistrer un commentaire