Turn on thread page Beta

if/else statements accepting strings in both capital and lower-case letters in python watch

    • Thread Starter

    Is there a quick way for an "if" statement to accept a string regardless of whether it's lower-case, upper-case or both in python?

    I'm attempting to write a piece of code where the number "3" can be entered as well as the word "three"or "Three" or any other mixture of capital and lower-case and it will still be accepted will still be accepted by the "if" statement in the code. I know that I can use "or" to get it to accept "3" as well as any other string, however, don't know how to get it to accept the string in more than one case. So far I have:

    if (Class == "3" or Class=="three" ) :
    f=open("class3.txt", "a+" )
    • Thread Starter

    I no longer require an answer to this but for anyone else looking for one I have found out that you can

    if(Class=="3"orClass.lower()=="three" ) :
    f=open("class3.txt","a+" )

University open days

  1. University of Edinburgh
    All Departments Undergraduate
    Sat, 22 Sep '18
  2. University of Exeter
    Undergraduate Open Days - Penryn Campus Undergraduate
    Sat, 22 Sep '18
  3. Loughborough University
    General Open Day Undergraduate
    Sat, 22 Sep '18
Which accompaniment is best?
Useful resources

Study tools


Essay expert

Learn to write like a pro with our ultimate essay guide.

Thinking about uni already?

Thinking about uni already?

See where you can apply with our uni match tool

Student chat

Ask a question

Chat to other GCSE students and get your study questions answered.


Make study resources

Create all the resources you need to get the grades.


Create your own Study Plan

Organise all your homework and exams so you never miss another deadline.

Resources by subject

From flashcards to mind maps; there's everything you need for all of your GCSE subjects.


Find past papers

100s of GCSE past papers for all your subjects at your fingertips.

Help out other students

Can you help? Study help unanswered threads

Groups associated with this forum:

View associated groups

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.