The Python Language Petr Přikryl Part IIb Socrates IP, 15th June 2004 TU of Brno, FIT, Czech Republic
June 2004, Socrates IP... syntax, semantics and examples
June 2004, Socrates IP The Python Language 3 Objects are garbage collected l Automatic memory management. l Reference counting. l Cyclic references. l To decrease the reference counter: u rebind to None u use del
June 2004, Socrates IP The Python Language 4... example
June 2004, Socrates IP The Python Language 5... removing the name
June 2004, Socrates IP The Python Language 6 Simple statements l... do not look as function calls: u assignment u print u del u pass (def myFunction: pass) u return u raise u try / except u assert
June 2004, Socrates IP The Python Language 7 Built-in functions l Predefined functions, always available: u id() u type() u str() u repr()
June 2004, Socrates IP The Python Language 8 Block, indentation, readability l Indentation defines what is inside the block. l The more indent steps, the deeper the block is. l “Life is better without braces” (Eckel) l More strict formatting rules – more readable source. l Even those disgusted by missing braces do like it at the end (at least, no problem – Raymond).
June 2004, Socrates IP The Python Language 9 Programming constructions l if – elif – else l while l for
June 2004, Socrates IP The Python Language 10 if – elif – else
June 2004, Socrates IP The Python Language 11 elif is good... l Replacement for the switch statement:
June 2004, Socrates IP The Python Language 12 elif is not necessary
June 2004, Socrates IP The Python Language 13 while, the general loop
June 2004, Socrates IP The Python Language 14 for – iteration through all items l Not a counted loop. l No direct indexing. l More modern, iterators.
June 2004, Socrates IP The Python Language 15 for, simulation of the counted loop
June 2004, Socrates IP The Python Language 16 xrange() with step
June 2004, Socrates IP The Python Language 17 Functions l They use return: l Arguments are passed by references, any type:
June 2004, Socrates IP The Python Language 18 Generators l They use yield; iterators:
June 2004, Socrates IP The Python Language 19 Generators and their iterators
June 2004, Socrates IP The Python Language iterator
June 2004, Socrates IP The Python Language 21 The iteration inside while
June 2004, Socrates IP The End of Part II
June 2004, Socrates IP The Python Language capturing the exception
June 2004, Socrates IP The Python Language continue