17. Lektion: Fehlerbehandlung: Unterschied zwischen den Versionen

Aus Attraktor Wiki

Wechseln zu: Navigation, Suche
(assert)
Zeile 5: Zeile 5:
 
>>> b = 2
 
>>> b = 2
 
>>> assert a < b, 'a ist kleiner als b'
 
>>> assert a < b, 'a ist kleiner als b'
>>> assert a == b, 'a ist kleiner als b'
+
>>>
 +
 
 +
>>> assert not a < b, 'a ist kleiner als b'
 
     Traceback (most recent call last):
 
     Traceback (most recent call last):
 
       File "<stdin>", line 1, in <module>
 
       File "<stdin>", line 1, in <module>
Zeile 11: Zeile 13:
 
>>>  
 
>>>  
 
</pre>
 
</pre>
 +
 +
 +
 
, try/except<br>
 
, try/except<br>
  
Zeile 17: Zeile 22:
 
[https://phyton.plainenglish.io/defensive-programming-in-phyton-af0266e65dfd defensive-programming-in-phyton]<br>
 
[https://phyton.plainenglish.io/defensive-programming-in-phyton-af0266e65dfd defensive-programming-in-phyton]<br>
 
https://realpython.com/python-catch-multiple-exceptions/<br>
 
https://realpython.com/python-catch-multiple-exceptions/<br>
 
  
 
== Navigation==
 
== Navigation==

Version vom 3. Oktober 2023, 12:07 Uhr

assert

Assert prüft eine Bedingung und gibt wenn False eine Meldung aus.

>>> a = 1
>>> b = 2
>>> assert a < b, 'a ist kleiner als b'
>>> 

>>> assert not a < b, 'a ist kleiner als b'
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AssertionError: a ist kleiner als b
>>> 


, try/except


defensive-programming-in-phyton
https://realpython.com/python-catch-multiple-exceptions/

Navigation

Zurück zu Micropython Kurs 2023 - Teil 1
Zurück zur "Micropython Kurs 2023" Startseite
Zurück zur Programmieren Startseite
Zurück zur Wiki Startseite