Anyone Can Code.



Avi Bhattacharya

if is used before a condition to check create the first condition within a conditional construct. If it is satisfied, then the code within the if statement will be executed.

    x = 18
    if x > 10:
    print ('value greater than 10')
value greater than 10

    #Using booleans
    y = True 
    if y == True:

You can also use the logical operators and and or to create more than one condition since these operators return boolean values.

    x = 39
    if x < 10 and x >= 0: #ignore negative values for now
        print('number has a single digit')
    elif (x >= 10 and x < 100):    #you can break this line down to 'else, if x is greater than or equal to 10 and less than 100':
        print ('number has two digits')
number has two digits

That's it for this tutorial! Click Next to access the next tutorial!

❮ Back

Next ❯

Copyright © 2021, Q-Programming | Created by Arjun Sodhi, Balpreet Juneja and Sammarth Kumar | Developed and Designed by Sammarth Kumar