Tutorial by Examples

Exceptions are powerful, but a single overzealous except clause can take it all away in a single line. try: res = get_result() res = res[0] log('got result: %r' % res) except: if not res: res = '' print('got exception') This example demonstrates 3 symptoms of t...
A program can easily waste time by calling a processor-intensive function multiple times. For example, take a function which looks like this: it returns an integer if the input value can produce one, else None: def intensive_f(value): # int -> Optional[int] # complex, and time-consuming cod...

Page 1 of 1