Python Day 36 – truthy truths in and not in

A “truthy” truth are various ways to get boolean True/False from other variables. For instance, 0 is false and 1 is true. If there are no string or other values inside () or {}, it will evaluate to false.

One can use “in” to detect whether a certain character is inside a string. This can be useful with custom inputs, however you’ll need to account for lowercase/uppercase letters with the .casefold() function. For instance:

activity = input(“What are you doing? “)

if “blender” not in activity.casefold():
print(“no let’s do blender”)
print(“yay me too!”)

For this you can enter “blender” or “Blender” and get the same result!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: