USE PYTHON "OR" TO ASSIGN DEFAULT VALUES :

Consider the situation where in you need to assign default value when certain value is null / none.

Example:


def fun(list_arg):

      if list_arg:
          globallist = list_arg
      else:
          globallist = ["default", "value"]

      print "globallist = ", globallist


In the above example fun is the function receives list, later a globallist variable needed to initiate with the value received as argument only if list arg is not empty, If empty you need to assign default value ["default"value"]

The conventional way is use if else stmt.

TRICK:

Use the "OR" operator to assign it simply.


def fun(list_arg):

      globallist = list_arg or ["default", "value"]
      print "globallist = ", globallist


Since python considers [], "", {}, () as false, if list_arg is empty OR operator will assign default list with value ["default""value"]

Similarly you can use this trick on strings, dict and tuple etc....

Tats all life's easier when you choose python :)