5 tips for Python Beginners
For a novice, try these tricks if you haven’t already 1. Function to make a noun (adjective) from a verb or an adverb from a noun (adjective) def verbing ( s ): returns iflen(s) < 3 elses + ( 'ing' , 'ly' )[ 'ing' ins] >>> verbing( 'help' ) helping >>> verbing( 'helping' ) helpingly 2. use a bare “*” asterisk in function parameter lists to force the caller to use keyword arguments for certain parameters >>> def f ( a, b, *, c= 'x' , d= 'y' , e= 'z' ): ... return 'Hello' To pass the value for c, d, and e you will need to explicitly pass it as “key=value” named arguments: >>> f( 1 , 2 , 'p' , 'q' , 'v' ) TypeError: f() takes 2 positional arguments but 5 we...