How do I check if it is uppercase, lowercase, or mixed with upper case?

2
    print('-----')
    print('TESTE')
    print('-----')

    print()

    lista = ['Joao', 'Joaozinho', 'Rafael']
    print(lista)
    var = str(input('Digite algum dos nomes da lista:'))

    if var == 'Joao' or var == 'João' or var == 'joao' or var == 'JOao' or var == 'JOAO' or var == 'JOão':
    print('Qualquer coisa')

    elif var == 'Joaozinho' or var == 'JOAOZINHO' or var == 'joaozinho' or var == 'joaoZINHO':
    print('Qualquer coisa')

    elif var == 'RAFAEL' or var == 'Rafael' or var == 'RAfael':
    print('Qualquer coisa') 
Basically, what I want to do is the following, I want to check these exemplary names without having to make these various conditions, for example "RAFAEL", "Rafael", and "RAFAEL", even with some capital letters mixed with such as the latter "RAfael", how do I do this?

    
asked by anonymous 25.02.2017 / 02:02

2 answers

4

You do not have to! Simply convert the variable to lowercase (all lowercase) using .lower() , and then compare it to the lowercase version of the name.

So:

if var.lower() == "joao":
    print("Qualquer coisa")
elif var.lower() == "joaozinho":
    print("Qualquer coisa")
elif var.lower() == "rafael":
    print("Qualquer coisa")
    
25.02.2017 / 04:58
2

I did not understand exactly what you wanted, but I had the same reasoning as @Matheus Avellar

print('-----')
print('TESTE')
print('-----')
print()
lista = ['Joao', 'Joaozinho', 'Rafael']
print(lista)
var = raw_input('Digite algum dos nomes da lista:\n')
print('Voce digitou         =>'+'"'+var+'"'+' tudo misturado minusculo com maisculo'+'\n'+'Mas eu exibo correto =>'+'"'+var.lower().title())+'"'

See working at Ideone

    
25.02.2017 / 05:30