This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
notes:python_cheat_sheet [2026/09/13 08:35] 91.186.242.139 old revision restored (2026/06/07 21:28) |
notes:python_cheat_sheet [2026/09/16 09:45] (current) 216.73.216.94 old revision restored (2026/09/13 21:37) |
||
|---|---|---|---|
| Line 55: | Line 55: | ||
| * But strings can't be modified using slices or indexes. | * But strings can't be modified using slices or indexes. | ||
| * [[http:// | * [[http:// | ||
| + | * format-string % (tuple) allows use of printf formatting strings. Also string.format() . | ||
| ===== Control Flow ===== | ===== Control Flow ===== | ||
| Line 91: | Line 92: | ||
| from fib import fib1, fib2 | from fib import fib1, fib2 | ||
| </ | </ | ||
| - | * %%__name__%% is set to the name of the module or to %%__main__%% if called from the command line. | + | * __name__ is set to the name of the module or to __main__ if called from the command line. |
| * The search list for modules is the variable sys.path initialized from the directory containing the input script (or the current directory), PYTHONPATH and the installation-dependent default. | * The search list for modules is the variable sys.path initialized from the directory containing the input script (or the current directory), PYTHONPATH and the installation-dependent default. | ||
| * When a module is imported, a byte-code version is stored to module.pyc which speeds up successive loads. | * When a module is imported, a byte-code version is stored to module.pyc which speeds up successive loads. | ||
| Line 98: | Line 99: | ||
| * Packages can be used to group modules. Packages should be in a named directory with an __init__.py file optionally containing initialization code. E.g. import sound.effects.echo . | * Packages can be used to group modules. Packages should be in a named directory with an __init__.py file optionally containing initialization code. E.g. import sound.effects.echo . | ||
| * . is the current package, .. is the parent package etc. | * . is the current package, .. is the parent package etc. | ||
| - | |||
| - | ===== Input/ | ||
| - | |||
| - | * str() returns a readable representations, | ||
| - | * Strings have several formatting methods. | ||
| - | * [[ http:// | ||
| - | * To open a file <code python> open('/ | ||
| - | * File methods include read, readline, write. | ||
| - | * //pickle// contains load and dump methods for serializing objects. Support should be added for new object types. | ||