Things I like about python (living blog as I update it time to time)
PermalinkKeyword (Named) Arguments for functions
- No need to follow the order of the arguments while calling a function
def concate(str1, str2):
print(str1)
print(str2)
# I can pass str2 first, then str1
concate(str2="2nd", str1="1st")
#if I don't pass params by name, then I have to be careful about the position
concate("1st", "2nd")
PermalinkDefault value for function arguments
Suppose a function has 10 params. A caller needs to set only the 1st and 7th param.
- if the function sets default values, then the caller can only mention those 2 params by name while calling the function
def concate(str1, str2 = None, str3 = None):
print(str1)
print(str2)
# The caller can only pass the parameters relevant for the caller
# no need to pass all parameters even if the caller doesn't bother
# about those params
concate(str1="1st") # I don't care the other params
concate(str3="3rd", str1="1st") # I don't care param str1