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/07/23 04:35] 114.119.135.37 old revision restored (2026/07/17 22:34) |
notes:python_cheat_sheet [2026/07/24 15:24] (current) 47.79.201.32 old revision restored (2026/06/21 13:23) |
||
|---|---|---|---|
| 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 92: | Line 91: | ||
| 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 99: | Line 98: | ||
| * 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. | ||
| + | * // | ||
| + | * To open a file <code python> open('/ | ||
| + | * [[http:// | ||
| + | * //pickle// contains load and dump methods for serializing objects. Support should be added for new object types. | ||