Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| lehrkraefte:snr:informatik:python:boolsche-werte [2021/09/13 15:48] – Olaf Schnürer | lehrkraefte:snr:informatik:python:boolsche-werte [2022/01/11 19:41] (current) – [Boolesche Werte und Variablen] Olaf Schnürer | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ===== Boolesche Werte und Variablen ===== | ||
| + | |||
| + | <WRAP round info> | ||
| + | Die Wahrheitswerte '' | ||
| + | |||
| + | Boolesche Werte kann man mit den **logischen Verknüpfungen** '' | ||
| + | |||
| + | Achtung: Die Tabellen sind nur bei ausreichender Fensterbreite vernünftig lesbar. | ||
| + | <WRAP group> | ||
| + | |||
| + | <WRAP third column> | ||
| + | |||
| + | Logisches '' | ||
| + | <WRAP round box 60%> | ||
| + | |and ^ True ^ False ^ | ||
| + | ^ True | True | False | | ||
| + | ^ False | False | False | | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | <WRAP third column> | ||
| + | |||
| + | Logisches '' | ||
| + | <WRAP round box 60%> | ||
| + | |or ^ True ^ False ^ | ||
| + | ^ True | True | True | | ||
| + | ^ False | True | False | | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | <WRAP third column> | ||
| + | |||
| + | Logisches '' | ||
| + | <WRAP round box 50%> | ||
| + | | x ^ True ^ False ^ | ||
| + | | not x | False | True | | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | Eine Variable, die als Wert '' | ||
| + | |||
| + | </ | ||
| + | |||
| + | <WRAP round info> | ||
| + | Vergleiche liefern Boolesche Werte: | ||
| + | * '' | ||
| + | Achtung: Das einzelne Zeichen '' | ||
| + | </ | ||
| + | * '' | ||
| + | * ''<'', | ||
| + | </ | ||
| + | |||
| + | <WRAP round todo> | ||
| + | Welche Ausgaben erwartest du bei dem folgenden Programm? Erst denken, dann testen! | ||
| + | <code python> | ||
| + | print(True and False) | ||
| + | print(2 < 5) | ||
| + | print((235236235 < 2346346) or True) | ||
| + | |||
| + | a = (5 != 6) | ||
| + | # a ist eine Boolesche Variable | ||
| + | # Es ist erlaubt, hier die Klammern wegzulassen, | ||
| + | # Klammern verbessern aber oft die Lesbarkeit und dienen der Fehlervermeidung. | ||
| + | # (Nur als Vielprogrammierer wird man sich genau merken können, was staerker bindet.) | ||
| + | print(a) | ||
| + | |||
| + | b = not (False or (True and (2 < 5))) | ||
| + | print(b) | ||
| + | |||
| + | # Man kann auch Wahrheitswerte vergleichen | ||
| + | print(True != True) | ||
| + | print(True == (False or True)) | ||
| + | |||
| + | print((2 < 3) == (-1 <= 0)) | ||
| + | # Die Leerzeichen sind hier stets optional, dienen aber der besseren Lesbarkeit: | ||
| + | # print((2< | ||
| + | # hat dieselbe Bedeutung. | ||
| + | </ | ||
| + | Zur Information: | ||
| + | </ | ||
| + | |||
| + | ===== Link zur Kursseite ===== | ||
| + | |||
| + | [[lehrkraefte: | ||
| + | |||