Introducing: Truthy and Falsy values!
Truthy and Falsy Values!
Hi! Welcome to this section. We will discuss Truthy and Falsy values. They will be essential tools in your programming future.
Let’s get started!
Sometimes we may find if/elif/else statements like these:
Don’t worry! variables
num
and string
act as Truthy and Falsy values on these examples.
These examples are adapted to what we have learned so far in the course, but in subsequent weeks I will add examples illustrating how data structures that we will study can act as Truthy and Falsy values if they are empty or if they have elements.
NOTE: These concepts was taken from Mozilla Developer Network, the words true and false are NOT capitalized, but you must capitalize them in Python since it’s case sensitive.
Link to Truth Value Testing article in Python Documentation: https://docs.python.org/3/library/stdtypes.html#truth-value-testing
Time to practice!
Here are some examples of how Truthy and Falsy values work in Python’s shell and in a Boolean context (if/elif/else statements and While Loops):
Note: Indentation may look different but this is how its presented when you enter code with several lines directly in Python’s Shell.
Hope it helps!
If you have any questions, please ask them in the forums or right below this post, your classmates and Community TAs will always be there to help you!
Estefania.
Comments
Post a Comment