LoslegenKostenlos loslegen

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

Kurs anzeigen

Anleitung zur Übung

  • Write code to see if True equals False.
  • Write Python code to check if -5 * 15 is not equal to 75.
  • Ask Python whether the strings "pyscript" and "PyScript" are equal.
  • What happens if you compare booleans and integers? Write code to see if True and 1 are 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
Code bearbeiten und ausführen