Check String Contains Python Image Check String Contains Python

In this code snippet, we are going to look at how you can check if a string exists within a string in Python.

>>> planets = "my very excellent mother just served us nine pizzas"
>>> "very" in planets
True
>>> "venus" in planets
False

We can then use this in if statements like so:

planets = "my very excellent mother just served us nine pizzas"
if "just" in planets:
    print("Just is in the mnemonic")