Python: "If" as Truth Teller

Post Reply
User avatar
Jason
Site Admin
Posts: 767
Joined: Sun Dec 21, 2025 8:56 pm

Code: Select all

print(f"Jerry is 1 year of age.")

is_Jerry_old = bool(False)

if is_Jerry_old:

print(f"Jerry is old.")

else

print(f"Jerry is not old.")

# Will print out "Jerry is not old." with no parentheses.

print(f"Larry is a cat. ")

is_larry_a_cat = bool(No)

If is_larry_a_cat:

print(f"Larry is a cat.")

else:

print(f"Larry is not a cat.")

# The code will print out "Larry is a cat." 
# but Larry being a cat is unknown. 
#The problem is that without a 
#specific true or 
#false, the code will only test
# if the variable has a
 #value, known as True, or does not, 
 # known as False.







 

POSTREACT(ions) SUMMARY

Post Reply