What can I write for an if condition?


#1

Question

What can I write for an if condition?

Answer

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
#2

2 posts were split to a new topic: How to Use return?


#3

what is - return true - what does it mean ? can you give examples please :frowning: