Control Flow
Reference
If Statements
Reference:
Use "If" statements to handle conditional logic (i.e. checking whether or not something is true and responding accordingly).
In Python, an "If" statement is defined using the if
keyword, followed by a condition to be evaluated, followed by a colon (:
), followed by one or more indented lines which contain statement(s) to be executed if the condition is met.
An "If" statement may include an else
keyword, followed by a colon (:
), followed by one or more indented lines which contain statement(s) to be executed if the original condition is not met.
An "If" statement, regardless of whether or not it contains an else
keyword, can contain any number of elif
keywords, each followed by a colon (:
), followed by one or more indented lines which contain statement(s) to be executed if the condition is met. If there is an else
keyword, it should come last.
As in other languages, statement order matters:
Case Statements
Python doesn't have "Case" statements. Try to use an "If" statement or a dictionary to accomplish what you are trying to do.
Last updated