Lowercase the string entered in Python

Asked 2 years ago, Updated 2 years ago, 14 views

warn_investment_list = ["Microsoft", "Google", "Naver", "Kakao", "SAMSUNG", "LG"]

word = input ("input: ")

if word in warn_investment_list:
    print ("This is an investment warning stock")
else:  
    print ("Not an investment warning stock")

=============================================================================== This code says that if you enter Microsoft, it is not an investment warning item.

To recognize even when entering lowercase letters like Microsoft

Should I write word.lower?

python

2022-09-20 22:32

1 Answers

>>> warn_investment_list = ["Microsoft", "Google", "Naver", "Kakao", "SAMSUNG", "LG"]
>>> l = [x.lower() for x in warn_investment_list]
>>> l
['microsoft', 'google', 'naver', 'kakao', 'samsung', 'lg']


2022-09-20 22:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.