0

I'm just starting to learn python and I am having some issues in comparing strings. I tried to look around but even after trying "==" and "is" and "eq()", my program still does not work.

I am used to working in Java, am I missing some sort of logic? Here is my code:

name = "John Smith"
name2 = name.lower
lowerName = name.lower

if name2 is lowerName:
    print("it is the same name") #this is never outputted
Nicole K
  • 3
  • 5
  • 1
    `.lower` doesn't call the function. Try `.lower()`. – Chris Apr 19 '20 at 22:26
  • 1
    Also, don't use `is` to compare strings. Use `==`. – Chris Apr 19 '20 at 22:26
  • "is" is used to assert if the variables are refering to the same object, that's why the if condition is not fulfilled. Also, as the other comments are saying, you should call lower as `lower()`. – Ralvi Isufaj Apr 19 '20 at 22:33

1 Answers1

0

You need to call the lower() function and use the == when comparing strings (since you are comparing the values, not the identities of the objects)

name = "John Smith"
name2 = name.lower()
lowerName = name.lower()

if name2 == lowerName:
    print("it is the same name")
Grand Phuba
  • 2,718
  • 1
  • 11
  • 19