Python 3 Programming Tutorial: If Elif Else

Home/Programming Video Tutorials/Python Video Tutorials/Python 3 Programming Tutorial: If Elif Else

Python 3 Programming Tutorial: If Elif Else

FavoriteLoadingAdd to favorites

Now we bring the in “elif” statement. The elif allows us to tie multiple if statements together as we might have intended to before with multiple if statements before we learned that the else will only be contingent on the if statement above it.

The “elif” statement is a hybrid of the else and the if. The way it works is:

We ask if something is the case. If it is, then the elif and the else will not run. If it is not, then the elif will run and question the if statement. If it is True, then it will run and the else will not run. If it is not true, then the else statement will run.

Sample code for this basics series: http://pythonprogramming.net/beginner-python-programming-tutorials/

Python 3 Programming tutorial Playlist: http://www.youtube.com/watch?v=oVp1vrfL_w4&feature=share&list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M

In this python 3 programming tutorial video, you are shown how to use the if elif else statements.

http://seaofbtc.com
http://sentdex.com
http://hkinsley.com

Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6

By | 2017-06-10T01:39:21+00:00 June 10th, 2017|Python Video Tutorials|37 Comments

37 Comments

  1. Jordan Socha June 10, 2017 at 1:40 am - Reply

    So, does Python use if/elif/else to handle switch/cases?

  2. chaitanya surepally June 10, 2017 at 1:42 am - Reply

    its is a nice lecture

  3. Chantapat Sheanakul June 10, 2017 at 1:45 am - Reply

    when I try to use elif it comes up as a syntax error.

  4. Sickguy Jam June 10, 2017 at 1:45 am - Reply

    PLEASE name your titles by parts it hard to find the next video

  5. Anthony Layne June 10, 2017 at 1:47 am - Reply

    What is the point of running elif? can’t it be replaced with multiple if statements?

  6. akshay mukesh June 10, 2017 at 1:54 am - Reply

    i have a question, how do we take input from the user and then compare them?

  7. Danielle Miller June 10, 2017 at 1:55 am - Reply

    so im new to this programming stuff with python too. I have an assignment that I need to do it wants me to determine the season by the month. my teacher wants me to use this if, elif, else statements how would I do that?please help me oout

  8. Tazlashawn June 10, 2017 at 1:56 am - Reply

    I keeping getting an invalid syntax error.

  9. PolaBoy June 10, 2017 at 1:56 am - Reply

    Will you also teach how to build a website from scratch using Django ? Thanks.

  10. Sohail Sayed June 10, 2017 at 1:57 am - Reply

    if maths<=24 and Evs<=24 and English<=24:print("You failed")
    else:print("You passed")
    Syntax error why?

  11. Dani Hana June 10, 2017 at 2:04 am - Reply

    hi. do you have videos on how to change if elif staements into dictionaries to make things look neater?

  12. Robert Baloyan June 10, 2017 at 2:08 am - Reply

    Thanks for your wonderful videos. A little question. If I want to see the outcome of both in case of they both are right statements, and outcome of rejection in the case of they both are false statements? how can I manage this problem? thanks in advance.

  13. BUFFDOENUT950 June 10, 2017 at 2:10 am - Reply

    import re

    print("Our Magical Calculator")
    print("Type ‘quit’ to exitn")
    previous = 0
    run = True

    def performMath():
    global run
    global previous
    equation = ""
    if previous == 0:
    equation = input("Enter equation:")
    else:
    equation = input(str(previous))
    #How do I set the equation to 0 so that it is set as "Enter equation"?<<<<<<<<<—-

    if equation == ‘quit’:
    print("Goodbye vro!")
    run = False
    else:
    equation = re.sub(‘[a-zA-Z,.:()" "]’, ”, equation)

    if previous==0:
    previous = eval(equation)

    else:
    previous =eval(str(previous)+ equation)

    while run:
    performMath()

  14. Did You Know That?! June 10, 2017 at 2:12 am - Reply

    how do i save and run it on mac? i really dont knoW!

  15. Bootje Banana June 10, 2017 at 2:12 am - Reply

    Just a simple straightforward tutorial! I like that!

  16. kirollos magdy June 10, 2017 at 2:12 am - Reply

    thank you … i’ve just made my first pythin code

  17. calskin June 10, 2017 at 2:12 am - Reply

    Just wanted to say, I really appreciate these videos.  Thanks for all of the work.

  18. Fahima Hossain June 10, 2017 at 2:16 am - Reply

    your videos are amazing 🙂

  19. Daphne Splyntr June 10, 2017 at 2:18 am - Reply

    I’m a Network Engineer starting my Python class next week and just warming up. I have seen hundreds of hours of videos on different Microsoft and networking topics from companies such as TrainSignal and CBT Nuggets over the years and I must say your training is excellent.

    Videos are short and informal. Keep up the good work!

  20. maris rose June 10, 2017 at 2:18 am - Reply

    wow I really like how this was explained. 🙂

  21. U2bingDummy June 10, 2017 at 2:18 am - Reply

    Can you teach how to make a program that detects sound? 

  22. Hellmut Kohlsdorf June 10, 2017 at 2:18 am - Reply

    Is this function the way Pathon implements the "case" instruction and this means "case" instruction does not exist?

  23. sanjeevani kumbhar June 10, 2017 at 2:21 am - Reply

    for example, if we take a program to find whether a year is a leap or not. We need 2 3 conditions to be true and then go ahead. So, in that case are we not supposed to use these statements to code? If my first condition is true it won’t go to next!!

  24. Borislav Konstantinov June 10, 2017 at 2:23 am - Reply

    I`m digital compositor and colourist works with Nuke and Davinci Resolve. It`s very handy for me to know Python. This videos are perfect for starting. Just for one week, and now I make my custom tools and gizmos in Python. Thank you!

  25. Onkar Kubal June 10, 2017 at 2:24 am - Reply

    Hi ,
    I am new to Python. I find your videos are great starting point for learning. My question is regarding conditional statements.
    Why there are no switch statements in Python?

  26. alemazzuca June 10, 2017 at 2:25 am - Reply

    How can we make the program to check 2 conditions such as if x> 5 AND is in the variable M array?

  27. JanJonDijonMustard June 10, 2017 at 2:27 am - Reply

    Does anyone know if you can put an elif statement as your first logic test or does it have to come after an if statement?

  28. ayman baroudi June 10, 2017 at 2:28 am - Reply

    Great and informative…

  29. Joe Kim June 10, 2017 at 2:28 am - Reply

    Thank you so much for the great tutorial videos 🙂

  30. ph0enixrid3r June 10, 2017 at 2:30 am - Reply

    your video is perfect for a beginner like me, thanks for excellent teaching.

  31. Mr.Kristian252 June 10, 2017 at 2:30 am - Reply

    thanks

  32. Venugopal Reddy June 10, 2017 at 2:32 am - Reply

    Thanks a lot for sharing the python video tutorials

    i have i question can we use for loop and else condition at a time.

  33. PolaBoy June 10, 2017 at 2:34 am - Reply

    Basically "elif" is the "else if" in other programming languages 😉

  34. Python Programmer June 10, 2017 at 2:36 am - Reply

    # Using If, Elif, Else

    def rerun_gender (): # Defines rerun_gender
        gender ()        # Runs the program called gender 

    def gender ():                        # Defines gender
        print ("Are you Male or Female?") # prints "Are you Male or Female?"
        choice = input ("")               # Lets you answer

    # The thing below means if any of those become True, it will activate the thing its ment to.
    # True + True = True, True + False = True, False + False = False, ("This doesnt matter how many True/Falses there are, in an
    # Or statement, aslong as 1 is true, it activates.

        if choice == ‘m’ or  choice == ‘M’ or choice == ‘male’ or choice == ‘Male’ or choice == ‘MALE’: # If choice == (Then the thing in ”)
            print ("You are male!")                                                                     # prints "You are male!"

        elif choice == ‘f’ or choice == ‘F’ or choice == ‘female’ or choice == ‘Female’ or choice == ‘FEMALE’: # Or if choice == (Then the thing in ”)
            print ("You are female!")                                                                          # prints "You are female!"

        else:                                           # If your response didnt match/fit in to any of the above:
            print ("Invalid Reponse!, answer with M/F") # prints "Invalid Reponse!, answer with M/F"
            rerun_gender ()                             # Runs rerun_gender

    gender () # Runs the program called gender

  35. james88 June 10, 2017 at 2:38 am - Reply

    Is elif the one to use if you have many parameters

  36. Ishank Sharma June 10, 2017 at 2:38 am - Reply

    thanks for the videos you are making a brighter future for people

  37. HAREEM GUL June 10, 2017 at 2:38 am - Reply

    how to write a programe having some working hours and salary of 50 workesr and effeciency with respect to time then we add 2500 bonous to the salary of one worker which works more effeciently???????
    plz plz help me out

Leave A Comment

*