Ignore if uppercase and lowercase in string

1
n1 = input('Qual é o seu bolo favorito?')

if n1 = 'Bolo de Chocolate':
   print('teste123')

If you write "Chocolate Cake" all in lowercase or all in uppercase, it will end up happening not to enter the if that I created, does anyone know if you have a function that ignores if it is uppercase or lowercase? / p>     

asked by anonymous 26.10.2018 / 23:22

2 answers

4

You can use lower() to turn everything into a lowercase. Whenever you have a question about whether you have a function to do something, you can look in the official documentation for the type of data you are working on. It would look like this:

n1 = input('Qual é o seu bolo favorito?')
if n1.lower() == 'bolo de chocolate':
    print('teste123')

See running on ideone . And no Coding Ground . Also I put GitHub for future reference .

I could use upper() too. Of course it does not solve all the other problems of the person typing different, which is much more likely to give some problem.

    
26.10.2018 / 23:34
3

You have to compare both versions in lowercase (or upper case). The .lower() function of a string transforms all characters into their lower case versions:

n1 = input('Qual é o seu bolo favorito?')

if n1.lower() == 'bolo de chocolate':
   print('teste123')
    
26.10.2018 / 23:34