- Function argument can be secified by position or by keywrod.
- Keywords make it clear what the purpose of each argument is when it would be confusing with only positional arguments
- Keyword arguments with default value make it easy to add new behaviors to a function, especially when the function has exsisting callers.
- Optional keyword arguments should always be passed by keyword instead of by position.
Effective Python
def remidner(number, divisor):
return number % divisor
It can be called by
reminder(20,7)
reminder(20, 7)
reminder(number=20, divisor=7)
reminder(divisor=7, number=20)
This expression is confusing.
twitter_search('@obama', False, 20, True)
twitter_search('@obama', retweets=False, numtweets=20, popular=True)
Is slightly (microseconds) slower but is worth it for the code clarity and developer time savings.