Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

398
Visualizações
'AttributeError: 'tuple' object has no attribute 'lower'' - Why doesn't the '.lower()' method doesn't work here in Python?

I am currently learning python and doing the exercises in the module. I have learned previously how to remove any case letter in the string, so it will be easier for the user to use it later on. But it seems like when I applied the ' XXX.lower() ' method to my code, it doesnt work. It works just fine without the '.lower()' method but I really want to know why it doest work ? Here's my code :

# bird names list
bird_names = ("Parrot", "Owl", "Pigeon", "Crow", "Peacock", "Hen")

# bird guess
bird_guess = input("Enter a bird name (Guess 1): ")

# nested conditions starts here
if bird_guess.lower() in bird_names.lower():
  print("Yes, 1st try!")
else:
  bird_guess = input("Enter a bird name (Guess 2): ")
  if bird_guess.lower() in bird_names.lower():
    print("Yes, 2nd try!")
  else:
    bird_guess = input("Enter a bird name (Guess 3): ")
    if bird_guess.lower() in bird_names.lower():
      print("Yes, 3rd try!")
    else:
      print("Sorry, out of tries.")
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

bird_names is a tuple, .lower() is supposed to be called on a string. You might want to consider something like

bird_names = ("Parrot", "Owl", "Pigeon", "Crow", "Peacock", "Hen")
bird_names = [name.lower() for name in bird_names]

and then you can use

if bird_guess.lower() in bird_names:
    ....
over 4 years ago · Santiago Trujillo Relatório

0

Because bird names is a tuple object not a string. In order for this to work what you can do is updating or overwriting the existing tuple with a list comprehension or generating a new variable. Instead of bird_names.lower() you can use the new list or tuple in the conditions.

bird_names_lower = [bird.lower() for bird in bird_names]
over 4 years ago · Santiago Trujillo Relatório

0

  • bird_names is a list object
  • .lower() is a string function

maybe something like this can help you:

if bird_guess.lower() in [word.lower() for word in bird_names]:
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda