Anyone Can Code.
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
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: print('success')success
You can also use the logical operators
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!