You are on page 1of 2
Conditional Statements: Takeaways & by Dataquest Labs, Inc. - All rights reserved © 2020 Syntax + Using an if statement to control your code: Af True: print) Mae prant(2) prant(s) * Combining multiple conditions: Af 3 > 1 and 2 rint("Both conditions are true!") AF 20 < 20 of 4c Drint(At Least one condition is true.") * Building more complex if statements: Af (20> 3 and 2 = 1) on ‘canes’ == ‘Ganes*: rint(*At Least one condition 4s true.") * Using the else clause: Af False print(a) else: Drint("The condition above was false.") + Using the elif clause: Af False: prine(a) elif 30> 5: Drint("The condition above was false.") Concepts + We-can use an ir statement to implement a condition in our code. + An air clause is executed if the preceding it statement (or the other preceding slit clauses) resolves to Fake and the condition specified after the it keyword evaluates to trae + tive and Fake are Boolean values. + and and or are logical operators, and they bridge two or more Booleans together. * We can compare a value A tovalue m to determine whether: +A isequal to Band vice versa(B is equal to 4) — = + 4 isnot equal to» and vice versa — + 4 isgreater than » or vice versa — > + 4 is greater than or equal to 8 or vice versa — = + 4 isless than B or vice versa — < + 4 isless than or equal to or vice versa — = Resources IfStatements in Python

You might also like