Python 3 Programming Tutorial: If Else

///Python 3 Programming Tutorial: If Else

Python 3 Programming Tutorial: If Else

FavoriteLoadingAdd to favorites

The If-Else statement is designed to build on the if statement’s logic. Here, we ask if something is the case, and, if it is we do something. Then we say otherwise, which is contingent on the previous if statement, do something else. If the previous if statement is true, then the else will not run. If the if statement is false, then the else statement will run.

Sample code for this basics series:

Python 3 Programming tutorial Playlist:

In this python programming tutorial video you are shown how to use the if-else statements together.

Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6

source

By |2019-05-06T18:45:44+00:00May 6th, 2019|Python Video Tutorials|31 Comments

31 Comments

  1. Veronica Toby May 6, 2019 at 6:45 pm - Reply

    Hi this is very easy to follow, very helpful. Thanks !

  2. Chaser ! May 6, 2019 at 6:45 pm - Reply

    when there is an add showing
    HOW TO STOP ADDS
    step 1. go to google and find add blocker
    step 2. watch this add
    #irony

  3. BlindRadio May 6, 2019 at 6:45 pm - Reply

    oh yeah yeah

  4. Johnithinuioian May 6, 2019 at 6:45 pm - Reply

    Awesome tutorial series!

  5. Lucas Mijota May 6, 2019 at 6:45 pm - Reply

    Dude slow the fuck down and use the correct strings/ examples otherwise people will get confused about what your printing or trying to convey

  6. Grant Robertson May 6, 2019 at 6:45 pm - Reply

    GEEEEEZ! BOTH if statements are running. It is the statements UNDER the if statements that may or may not be running, depending on the result of the comparison in the if statement.

  7. Muhammad Usama May 6, 2019 at 6:45 pm - Reply

    sir its so complicated and not understand

  8. Mizou Drs May 6, 2019 at 6:45 pm - Reply

    I wonder to know if there is a function that can solve such problem, imagine we have :
    a = 56123145678561615615615616515665156123145678561615615615616515665156123
    b = 56123145678561615615615616515665156123145678561615615615616515665157123
    numbers in A and B, seem to be equal but there is only one number which is not the same in B , is't possible to know what is the unmatched number in B using python ?

  9. Tanis Creation May 6, 2019 at 6:45 pm - Reply

    Hi , I am getting error while executing if else block in python 3.6.4 IDE shell  but same thing when I am executing in Terminal , it's working as expected . Could you please let me know the point of error.
    IDE Code / Error :

    >>> if x > y :
    print ('x')
    else :

    SyntaxError: invalid syntax

    Terminal : 

    >>> if x>y:
    …    print('x')
    … else :
    …    print('y')
    y

  10. John Bannister May 6, 2019 at 6:45 pm - Reply

    You're great at explaining this stuff man, thank you for posting these vids- very helpful

  11. sue mendez May 6, 2019 at 6:45 pm - Reply

    I like the large font you use it's easy to see the code, Thanks.

  12. Hidden Acc May 6, 2019 at 6:45 pm - Reply

    How x is greater than 55 when x is 5 you dumm dumm

  13. Justin Duijn May 6, 2019 at 6:45 pm - Reply

    This one is confusing, because if if is true, else is not and if else is true, if is not true.
    Confusing, but true, else, not true.

  14. Free Pokemon TCG online codes May 6, 2019 at 6:45 pm - Reply

    a=int(input("How old are you?"))
    if a >= 16 < 18:
    b=input("Are you at sixth form, work or at college?")
    print("You work at",b,".")
    if a > 18:
    c=input("Have you started taking driving lessons yet?")

    Why does this not work!!

  15. RagHelen May 6, 2019 at 6:45 pm - Reply

    I once had a girlfriend named Elif.

  16. Andreas Paalman May 6, 2019 at 6:45 pm - Reply

    I had a constant error with using else but thanks to your help i managed to create my first if else code and im really happy 😀
    Thank you!

  17. Princeton A. Strong May 6, 2019 at 6:45 pm - Reply

    Thanks for the tutorials!

  18. andre johan May 6, 2019 at 6:45 pm - Reply

    Best basic python series… even better than some of the paid courses!

    great work

  19. Noah Sanchez May 6, 2019 at 6:45 pm - Reply

    1:21 TTTRRRRIIIGGGEEERRRREEEDDD

  20. Mr HunterF λ May 6, 2019 at 6:45 pm - Reply

    Thankyou, just starting to learn python. subscribed.

  21. Isaiah Trigo May 6, 2019 at 6:45 pm - Reply

    python 3.6.ob4 is telling me the else statement and the elif statements are invalid syntax

  22. Logan Burke May 6, 2019 at 6:45 pm - Reply

    please, someone help me… This code is not working
    age = input()
    if age > int(13) :
    print("You can take this test :)")
    else:
    print ("You can't take this test.")
    print (" But I am really nice so I'm going to let you take it ")
    print ("Are you ready?")

  23. ahowl7mx May 6, 2019 at 6:45 pm - Reply

    Great series Sentdex, you helped me learn python over a weekend! General question, how do you make a new column and have an if-then statement in the new column? Example, I have two columns with different string lengths and I want a new column that will use either column if the length of the string is 13.

  24. Liam Blyth May 6, 2019 at 6:45 pm - Reply

    I have doneif phone=android:       print ("yay")what is wrong?? please help

  25. RankBabie Rank May 6, 2019 at 6:45 pm - Reply

    I wrote some code with multiple input statements at once for a simple RPG inventory tutorial. are you able to do that because it runs the if statement even lg the condition is not true. Ex.
    looting = input("Do you wish to continue?nyes or no.")
    if looting == "yes" or "Yes":
    print("Your character has just defeated a 'Basic Rouge'")
    with some other input staments in here.
    then at the bottom is
    else:
    print("I'm sorry you must have typed that wrong. You must restart the tutorial.")
    But even if i put 10 random letters in its still goes to the if statement and not the else.
    pls reply as fast as you can this is due tomorrow. its ok if you don't.

  26. isaac johnson May 6, 2019 at 6:45 pm - Reply

    Thankyou for this video it really helped me do my homework 🙂

  27. Atomic Potato May 6, 2019 at 6:45 pm - Reply

    How can you do this with variables that have an input e.g.
    understand = input('is that understood?')
    if understand == yes
    print('good, now lets move on')

  28. Freddy Camacho May 6, 2019 at 6:45 pm - Reply

    Does python have data vectors like c++?

  29. hangmanM1 May 6, 2019 at 6:45 pm - Reply

    Here's my code but it doesn't go to the else statement if the if statement is false. Everything else works besides if statement. 

      1 #!/bin/python
      2 var = raw_input ("hey, what's your name? ")
      3 print "hello,", var, "nice to meet you. What do you like to do?"
      4 var = raw_input()
      5 print var, "? I like to do that as well!"
      6 print "what do you like to eat? ",
      7 var = raw_input()
      8 print "I like to eat" ,var, "as well! But, I also like your mother's pussy. What is the temperature right now?"
      9 if raw_input() > 30:
     10   print ("As usual")
     11 else:
     12   print ("That's not possible")
    ~
    Any ideas y it won't go to else statement?
    Thanks in advance BTW.

  30. Haily Melendez May 6, 2019 at 6:45 pm - Reply

    I have to go to your videos because my computer programming teacher isn't great at explaining and I would like a nice grade. Thanks!

  31. U2bingDummy May 6, 2019 at 6:45 pm - Reply

    Actually, I know the if else and elif functions for Python. I've been working on a project that can detect if Radiostations are on the air or not. But I need someone to give me the source code of a program that can detect sound. Can you help?

Leave A Comment

*