for i, el in enumerate(<coll>, start=0): # Returns iterator of `(index+start, <el>)` tuples.
for i, el in enumerate(<coll>, start=0): # Returns next element and its index on each pass.
...
```
@ -981,20 +981,20 @@ class MyClass:
#### Expressions that call the str() method:
```python
print(<el>)
f'{<el>}'
logging.warning(<el>)
csv.writer(<file>).writerow([<el>])
raise Exception(<el>)
print(<obj>)
f'{<obj>}'
logging.warning(<obj>)
csv.writer(<file>).writerow([<obj>])
raise Exception(<obj>)
```
#### Expressions that call the repr() method:
```python
print/str/repr([<el>])
print/str/repr({<el>: <el>})
f'{<el>!r}'
Z = dataclasses.make_dataclass('Z', ['a']); print/str/repr(Z(<el>))
>>> <el>
print/str/repr([<obj>])
print/str/repr({<obj>: <obj>})
f'{<obj>!r}'
Z = dataclasses.make_dataclass('Z', ['a']); print/str/repr(Z(<obj>))
>>> <obj>
```
### Inheritance
@ -1415,14 +1415,14 @@ except (<exception>, [...]) as <name>: ...
* **Also catches subclasses of the exception.**
* **Use `'traceback.print_exc()'` to print the full error message to stderr.**
* **Use `'print(<name>)'` to print just the cause of the exception (its arguments).**
* **Use `'logging.exception(<message>)'` to log the passed message, followed by the full error message of the caught exception. For details see [logging](#logging).**
* **Use `'logging.exception(<str>)'` to log the passed message, followed by the full error message of the caught exception. For details see [logging](#logging).**
* **Use `'sys.exc_info()'` to get exception type, object, and traceback of caught exception.**
<div><h2id="enumerate"><ahref="#enumerate"name="enumerate">#</a>Enumerate</h2><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">for</span> i, el <spanclass="hljs-keyword">in</span> enumerate(<coll>, start=<spanclass="hljs-number">0</span>): <spanclass="hljs-comment"># Returns iterator of `(index+start, <el>)` tuples.</span>
<div><h2id="enumerate"><ahref="#enumerate"name="enumerate">#</a>Enumerate</h2><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">for</span> i, el <spanclass="hljs-keyword">in</span> enumerate(<coll>, start=<spanclass="hljs-number">0</span>): <spanclass="hljs-comment"># Returns next element and its index on each pass.</span>
...
</code></pre></div>
@ -826,18 +826,18 @@ player = Player(point, direction) <span class="hljs-comment">#
<div><h4id="expressionsthatcallthestrmethod">Expressions that call the str() method:</h4><pre><codeclass="python language-python hljs">print(<el>)
<div><h4id="expressionsthatcallthestrmethod">Expressions that call the str() method:</h4><pre><codeclass="python language-python hljs">print(<obj>)
<div><h4id="expressionsthatcallthereprmethod">Expressions that call the repr() method:</h4><pre><codeclass="python language-python hljs">print/str/repr([<el>])
<div><h4id="expressionsthatcallthereprmethod">Expressions that call the repr() method:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">print</span>/str/repr([<obj>])
Z = dataclasses.make_dataclass(<spanclass="hljs-string">'Z'</span>, [<spanclass="hljs-string">'a'</span>]); <spanclass="hljs-keyword">print</span>/str/repr(Z(<obj>))
<li><strong>Also catches subclasses of the exception.</strong></li>
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'traceback.print_exc()'</span></code> to print the full error message to stderr.</strong></li>
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'print(<name>)'</span></code> to print just the cause of the exception (its arguments).</strong></li>
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'logging.exception(<message>)'</span></code> to log the passed message, followed by the full error message of the caught exception. For details see <ahref="#logging">logging</a>.</strong></li>
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'logging.exception(<str>)'</span></code> to log the passed message, followed by the full error message of the caught exception. For details see <ahref="#logging">logging</a>.</strong></li>
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'sys.exc_info()'</span></code> to get exception type, object, and traceback of caught exception.</strong></li>
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'help=<str>'</span></code> to set argument description that will be displayed in help message.</strong></li>
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'default=<el>'</span></code> to set option's or optional argument's default value.</strong></li>
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'default=<obj>'</span></code> to set option's or optional argument's default value.</strong></li>
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'type=FileType(<mode>)'</span></code> for files. Accepts 'encoding', but 'newline' is None.</strong></li>
</ul>
<div><h2id="open"><ahref="#open"name="open">#</a>Open</h2><p><strong>Opens the file and returns a corresponding file object.</strong></p><pre><codeclass="python language-python hljs"><file> = open(<path>, mode=<spanclass="hljs-string">'r'</span>, encoding=<spanclass="hljs-keyword">None</span>, newline=<spanclass="hljs-keyword">None</span>)
<div><h3id="patterns">Patterns</h3><pre><codeclass="python language-python hljs"><value_pattern> = <spanclass="hljs-number">1</span>/<spanclass="hljs-string">'abc'</span>/<spanclass="hljs-keyword">True</span>/<spanclass="hljs-keyword">None</span>/math.pi <spanclass="hljs-comment"># Matches the literal or a dotted name.</span>
<class_pattern> = <type>() <spanclass="hljs-comment"># Matches any object of that type.</span>
<wildcard_patt> = _ <spanclass="hljs-comment"># Matches any object.</span>
<capture_patt> = <name><spanclass="hljs-comment"># Matches any object and binds it to name.</span>
<or_pattern> = <pattern> | <pattern> [| ...] <spanclass="hljs-comment"># Matches any of the patterns.</span>
<as_pattern> = <pattern><spanclass="hljs-keyword">as</span><name><spanclass="hljs-comment"># Binds the match to the name.</span>
<sequence_patt> = [<pattern>, ...] <spanclass="hljs-comment"># Matches sequence with matching items.</span>
<class_pattern> = <type>(<attr_name>=<patt>, ...) <spanclass="hljs-comment"># Matches object with matching attributes.</span>
<div><h3id="patterns">Patterns</h3><pre><codeclass="python language-python hljs"><value_pattern> = <spanclass="hljs-number">1</span>/<spanclass="hljs-string">'abc'</span>/<spanclass="hljs-keyword">True</span>/<spanclass="hljs-keyword">None</span>/math.pi <spanclass="hljs-comment"># Matches the literal or a dotted name.</span>
<class_pattern> = <type>() <spanclass="hljs-comment"># Matches any object of that type.</span>
<wildcard_patt> = _ <spanclass="hljs-comment"># Matches any object.</span>
<capture_patt> = <name><spanclass="hljs-comment"># Matches any object and binds it to name.</span>
<or_pattern> = <pattern> | <pattern> [| ...] <spanclass="hljs-comment"># Matches any of the patterns.</span>
<as_pattern> = <pattern><spanclass="hljs-keyword">as</span><name><spanclass="hljs-comment"># Binds match to name. Also <type>(<name>).</span>
<sequence_patt> = [<pattern>, ...] <spanclass="hljs-comment"># Matches sequence with matching items.</span>
<mapping_patt> = {<value_pattern>: <patt>, ...}<spanclass="hljs-comment"># Matches dictionary with matching items.</span>
<class_pattern> = <type>(<attr_name>=<patt>, ...) <spanclass="hljs-comment"># Matches object with matching attributes.</span>
</code></pre></div>
<ul>
@ -1878,23 +1878,23 @@ CRITICAL:my_module:Running out of disk space.
2023-02-07 23:21:01,430 CRITICAL:my_module:Running out of disk space.
</code></pre></div>
<div><h2id="introspection"><ahref="#introspection"name="introspection">#</a>Introspection</h2><pre><codeclass="python language-python hljs"><list> = dir() <spanclass="hljs-comment"># Names of local variables, functions, classes, etc.</span>
<dict> = vars() <spanclass="hljs-comment"># Dict of local variables, etc. Also locals().</span>
<dict> = globals() <spanclass="hljs-comment"># Dict of global vars, etc. (incl. '__builtins__').</span>
<div><h2id="introspection"><ahref="#introspection"name="introspection">#</a>Introspection</h2><pre><codeclass="python language-python hljs"><list> = dir() <spanclass="hljs-comment"># Names of local vars, functions, classes and modules.</span>
<dict> = vars() <spanclass="hljs-comment"># Dict of local vars, functions, etc. Also locals().</span>
<dict> = globals() <spanclass="hljs-comment"># Dict of global vars, etc. (including '__builtins__').</span>
<dict> = vars(<object>) <spanclass="hljs-comment"># Dict of writable attributes. Also <obj>.__dict__.</span>
<bool> = hasattr(<object>, <spanclass="hljs-string">'<attr_name>'</span>) <spanclass="hljs-comment"># Checks if getattr() raises an AttributeError.</span>
value = getattr(<object>, <spanclass="hljs-string">'<attr_name>'</span>) <spanclass="hljs-comment"># Default value can be passed as the third argument.</span>
setattr(<object>, <spanclass="hljs-string">'<attr_name>'</span>, value) <spanclass="hljs-comment"># Only works on objects with __dict__ attribute.</span>
delattr(<object>, <spanclass="hljs-string">'<attr_name>'</span>) <spanclass="hljs-comment"># Same. Also `del <object>.<attr_name>`.</span>
<pre><codeclass="python language-python hljs"><list> = dir(<obj>) <spanclass="hljs-comment"># Names of all object's attributes (including methods).</span>
<dict> = vars(<obj>) <spanclass="hljs-comment"># Dict of writable attributes. Also <obj>.__dict__.</span>
<bool> = hasattr(<obj>, <spanclass="hljs-string">'<attr_name>'</span>) <spanclass="hljs-comment"># Checks if getattr() raises AttributeError.</span>
value = getattr(<obj>, <spanclass="hljs-string">'<attr_name>'</span>) <spanclass="hljs-comment"># Default value can be passed as the third argument.</span>
setattr(<obj>, <spanclass="hljs-string">'<attr_name>'</span>, value) <spanclass="hljs-comment"># Only works on objects with __dict__ attribute.</span>
delattr(<obj>, <spanclass="hljs-string">'<attr_name>'</span>) <spanclass="hljs-comment"># Same. Also `del <object>.<attr_name>`.</span>
<li><strong>Coroutines have a lot in common with threads, but unlike threads, they only give up control when they call another coroutine and they don’t use as much memory.</strong></li>
<li><strong>All <codeclass="python hljs"><spanclass="hljs-string">'cdef'</span></code> definitions are optional, but they contribute to the speed-up.</strong></li>
<li><strong>Script needs to be saved with a <codeclass="python hljs"><spanclass="hljs-string">'pyx'</span></code> extension.</strong></li>