25% off

Use code FUNCMAIN at checkout for 25% off all premium courses.

Get started →
Check String Contains Python
Code Snippet

Check String Contains Python

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")