+ 1

Upper in if statment

I make list and i put some names then the user will put a name and i want to check if the name exist in the list but in lowecase

30th Oct 2019, 7:55 PM
Yassine Rezgui
Yassine Rezgui - avatar
5 Antworten
+ 3
Simply: name = input ("enter the name") if name in list: do sth it searches the name as you entered (whether upper or lower)
30th Oct 2019, 9:31 PM
Qasem
+ 3
from my point of view it makes sense to store the names in correct spelling in the list as we have not full control how user will input a name for search, we convert both (name in list and input) temporarely for comparison to lower() or upper() or casefold() ''' lst = ['Nora', 'Frank', 'Lisa', 'Dany'] inp = 'franK' print('found') if inp.lower() in ''.join(lst).lower() else print('not found') # or instead printing: if inp.lower() in ''.join(lst).lower(): print('found') # do something
30th Oct 2019, 10:20 PM
Lothar
Lothar - avatar
+ 2
names = ["Jack", "Paul", "Sam"] find = input("Enter name:- ") if find.lower() in [x.lower() for x in names[:]]: print(True)
30th Oct 2019, 10:47 PM
rodwynnejones
rodwynnejones - avatar
+ 1
There are several functions to make a string completely uppercase or lowercase : string = "Hello" up = string.upper() #HELLO down = string.lower() #hello
30th Oct 2019, 8:21 PM
Théophile
Théophile - avatar
+ 1
use this code: str=input('please enter name: ') if str in list: if str.lower()==str: print('its lower') else: print('its upper')
31st Oct 2019, 2:49 PM
Mohammad Gk
Mohammad Gk - avatar