Javaist learning Python – Part 2 – conditions

I will write about what something I found funny – the conditions

  1. Python has a elif statement. This makes the code easier to read. Python you have a +1 from me for this
  2. Ok… now we go to the part where we find that one does not need to check for a boolean condition. Not only it does not need to check for this, it is advised NOT to check against False, True or None (a singleton that is somehow similar to the null in Java). Everything except the next statements are considered True(This reminded me of highschool and C++):
    • None
    • False
    • zero – for numeric types
    • empty dictionaries, sequences
    • 0 returned when calling __length__
    • False returned when __nonzero__ is called
  3. Now, an even stranger thing: one can have an else after a for… say whaat? yep… One can face something like
    for loop:
        if condition:
    So, what is this all about? The statement is executed when after the program finished the loop… Every time, with one exception: when a break was executed inside the loop. I still have mixed feelings about this, but probably after using more of it, it will come natural.

This was all from my Python adventure till this moment.

Leave a Reply

Your email address will not be published. Required fields are marked *