0

While learning Python I stumbled upon a conditional statement that doesn't have a full condition and I can't seem to figure out the use.

if number: print ("2")

What is being compared to number? I can't seem to figure out when it's true and when it's false.

4
  • This basically just checks if the value of number isn't Null. If number has a value (doesn't matter what value except Null or None) it prints "2". Commented Jan 27, 2017 at 15:41
  • Should be true if it's not equal to 0. Right? Commented Jan 27, 2017 at 15:41
  • 3
    no, could be None, empty list/tuple/dict, everything that is "falsy" Commented Jan 27, 2017 at 15:41
  • 1
    You might want to check this... Commented Jan 27, 2017 at 15:43

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.