Equality
To check if two Python values, or variables, are equal you can use ==. To check for inequality, you need !=. As a refresher, have a look at the following examples that all result in True. Feel free to try them out.
2 == (1 + 1)
"intermediate" != "python"
True != False
"Python" != "python"
When you write these comparisons in a script, you will need to wrap a print() function around them to see the output.
Diese Übung ist Teil des Kurses
Intermediate Python
Anleitung zur Übung
- Write code to see if
TrueequalsFalse. - Write Python code to check if
-5 * 15is not equal to75. - Ask Python whether the strings
"pyscript"and"PyScript"are equal. - What happens if you compare booleans and integers? Write code to see if
Trueand1are equal.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Comparison of booleans
# Comparison of integers
# Comparison of strings
# Compare a boolean with an integer