Skip to content

Commit 7581f96

Browse files
committed
Exceptions, exit, print
1 parent ed3293a commit 7581f96

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,8 +1388,8 @@ except <exception>:
13881388

13891389
#### Useful built-in exceptions:
13901390
```python
1391-
raise ValueError('Argument is of right type but inappropriate value!')
13921391
raise TypeError('Argument is of wrong type!')
1392+
raise ValueError('Argument is of right type but inappropriate value!')
13931393
raise RuntimeError('None of above!')
13941394
```
13951395

@@ -1439,13 +1439,24 @@ class MyInputError(MyError):
14391439
```
14401440

14411441

1442+
Exit
1443+
----
1444+
**Exits the interpreter by raising SystemExit exception.**
1445+
```python
1446+
import sys
1447+
sys.exit() # Exits with exit code 0 (success).
1448+
sys.exit(<int>) # Exits with passed exit code.
1449+
sys.exit(<obj>) # Prints the object and exits with 1 (failure).
1450+
```
1451+
1452+
14421453
Print
14431454
-----
14441455
```python
14451456
print(<el_1>, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
14461457
```
14471458

1448-
* **Use `'file=sys.stderr'` for errors.**
1459+
* **Use `'file=sys.stderr'` for messages about errors.**
14491460
* **Use `'flush=True'` to forcibly flush the stream.**
14501461

14511462
### Pretty Print

index.html

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,8 +1302,8 @@
13021302
<span class="hljs-keyword">raise</span>
13031303
</code></pre></div>
13041304

1305-
<div><h4 id="usefulbuiltinexceptions">Useful built-in exceptions:</h4><pre><code class="python language-python hljs"><span class="hljs-keyword">raise</span> ValueError(<span class="hljs-string">'Argument is of right type but inappropriate value!'</span>)
1306-
<span class="hljs-keyword">raise</span> TypeError(<span class="hljs-string">'Argument is of wrong type!'</span>)
1305+
<div><h4 id="usefulbuiltinexceptions">Useful built-in exceptions:</h4><pre><code class="python language-python hljs"><span class="hljs-keyword">raise</span> TypeError(<span class="hljs-string">'Argument is of wrong type!'</span>)
1306+
<span class="hljs-keyword">raise</span> ValueError(<span class="hljs-string">'Argument is of right type but inappropriate value!'</span>)
13071307
<span class="hljs-keyword">raise</span> RuntimeError(<span class="hljs-string">'None of above!'</span>)
13081308
</code></pre></div>
13091309

@@ -1346,11 +1346,18 @@
13461346
<span class="hljs-keyword">pass</span>
13471347
</code></pre></div>
13481348

1349+
<div><h2 id="exit"><a href="#exit" name="exit">#</a>Exit</h2><p><strong>Exits the interpreter by raising SystemExit exception.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">import</span> sys
1350+
sys.exit() <span class="hljs-comment"># Exits with exit code 0 (success).</span>
1351+
sys.exit(&lt;int&gt;) <span class="hljs-comment"># Exits with passed exit code.</span>
1352+
sys.exit(&lt;obj&gt;) <span class="hljs-comment"># Prints the object and exits with 1 (failure).</span>
1353+
</code></pre></div>
1354+
1355+
13491356
<div class="pagebreak"></div><div><h2 id="print"><a href="#print" name="print">#</a>Print</h2><pre><code class="python language-python hljs">print(&lt;el_1&gt;, ..., sep=<span class="hljs-string">' '</span>, end=<span class="hljs-string">'\n'</span>, file=sys.stdout, flush=<span class="hljs-keyword">False</span>)
13501357
</code></pre></div>
13511358

13521359
<ul>
1353-
<li><strong>Use <code class="python hljs"><span class="hljs-string">'file=sys.stderr'</span></code> for errors.</strong></li>
1360+
<li><strong>Use <code class="python hljs"><span class="hljs-string">'file=sys.stderr'</span></code> for messages about errors.</strong></li>
13541361
<li><strong>Use <code class="python hljs"><span class="hljs-string">'flush=True'</span></code> to forcibly flush the stream.</strong></li>
13551362
</ul>
13561363
<div><h3 id="prettyprint">Pretty Print</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> pprint <span class="hljs-keyword">import</span> pprint

0 commit comments

Comments
 (0)