Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialItsa Snake
3,852 PointsPython: if statement with string, ignoring case
Is it possible to check if a string matches a value, ignoring the case?
e.g. first_name = input("your first name") if first_name == "Sam": #do something
The above would only work if they entered Sam not sam
2 Answers
Steven Parker
231,248 PointsCase insensitivity is commonly achieved by converting the string case and matching against a pre-converted literal:
if first_name.upper() == "SAM":
Itsa Snake
3,852 Pointswell that's incredibly logical. Thanks very much