False return when comparing two python identical strings

Asked

Viewed 260 times

0

I’m trying to compare two strings, one comes from the database as an array, the other is written by hand:

  string = str(profile[1]) #Carlos Gimenes
  print(string == str('Carlos Gimenes'))
  #Retorna false

I have tried several ways and I can’t make this return true, by displaying the type of the variable is returned that both are <class 'str'>, still the returned value continues as false.

project link:https://github.com/CaduGimenes/recognizer

  • 2

    needless to convert using str, redundant. I do a simple debug to ensure even if equal: string = str(profile[1]); string2 = 'Carlos Gimenes'; print(string, string2, Sep=' n')

1 answer

0


I checked the binary of the project database and as the image below may be that there is a typo at the time of having added the test data and therefore the result of the expression string == str('Carlos Gimenes' is false.inserir a descrição da imagem aqui

In the image we verify the existence of 'Carlos Gimenesv' with the V at the end of the string.

As @Eltonnunes said just compare string values in the console and check if the values are in fact equal.

This kind of problem happens in ways we don’t understand and it’s most commendable perform these initial checks to discover the problem, in case verify the actual value of the variable.

print(string, string2, sep='\n')
  • 1

    It worked out thank you very much, for some reason the data was being inserted with space before and after.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.