What can I write for an if condition?



What can I write for an if condition?


Any expression that results in True or False is a viable condition for an if statement in Python. There are endless possibilities of things you could combine to make such an expression, but some we’ve learned so far are:

  • Expressions using comparators like ==, >, etc.
  • Expressions using not, and, and or
  • But there are other ways to express truth values! For example, we can return a value from a function and check that value returned, or even just return True or return False and then write if function_name(). Another possibility is using 0 for False and 1 for True!

FAQ: Learn Python - Conditionals & Control Flow - If You're Having