python-cheatsheet

Control flow

Conditional statements

These commands require strict indentation

Method Explanation Usage
if If condition met, execute: if a==b:
elif If previous condition not met AND condition met, execute: elif a==c:
else If no previous conditions met, execute: else:

Iterative statements

These commands require strict indentation

Method Explanation Usage
for Per each item in a sequence, execute: Sets item to seq value for item in sequence:
while While condition is met, execute: while i<5:

Transfer statements

Method Explanation
break Terminate the loop statement, continue execution after loop
continue Skip the remainder of the body of loop statement, continue with next test