Anything with a non-zero length is true, empty sequences are false : Boolean « Data Type « Python






Anything with a non-zero length is true, empty sequences are false

Anything with a non-zero length is true, empty sequences are false

if []:
   print "empty."
  
if [1]:
   print "not empty."
  
if ():
   print "empty."
  
if (1):
   print "not empty."

if {}:
   print "empty."
  
if {1:0}:
   print "not empty."

           
       








Related examples in the same category

1.Boolean operation in ifBoolean operation in if
2.In Python any non-zero integer value is true; zero is false.In Python any non-zero integer value is true; zero is false.