Home > Software design >  Can you make an if statement that accepts any combination of upper and lowercase letters in a specif
Can you make an if statement that accepts any combination of upper and lowercase letters in a specif

Time:08-02

Can you make an if statement that accepts any combination of upper and lowercase letters in a specific input string in Python such as "You", or "YUo"?

CodePudding user response:

You could modify the string so that everything is lowercase like this:

user_input = input("Say something: ")

if user_input.lower() == "you":
    print("hi")

CodePudding user response:

Any combination can be achieved with set()

input_str = 'YUo' # 'You' 'oYu'
match_str = 'you'
if set(input_str.lower()) == set(match_str):
    print('matched')

CodePudding user response:

You could use ternary operators to check this like following:

True if False not in [True if (i.lower() in y.lower()) else False for i in x] else False
  • Related