Search code examples
pythonequality-operator

Equality operator (==) has no effect


I am currently following through a book (Python Crash Course), and have just been introduced to the '==' equality operator.

In the book, it shows setting a variable and checking whether it is equal to itself (using ==). See below.

Also tried numerical comparisons and having the same issue as outlined below.

car = "bmw"
car == "bmw"

This is providing no output and PyCharm is telling me 'car == "bmw" has no effect. Book is telling me it should be responding "True" as I am checking the variable which I have literally JUST set.


Solution

  • Try:

    car = "bmw"
    print(car == "bmw")
    

    Or type your code directly in the console. Just running your script like that won’t produce anything, because you don’t do anything with the comparison.