Python Tutorials - Herong's Tutorial Examples - v2.14, by Herong Yang
What Is Statement
This section provides a quick introduction of statement, which is the smallest unit of code that can be sent to the Python system to execute.
What Is Statement? A statement is a smallest unit of code that can be sent to the Python system to execute.
There are 2 groups of statements supported in Python: simple statements and compound statements.
1. What Is Simple Statement? A simple statement is a unit of executable code containing no sub-statements.
There are 4 basic rules on writing a simple statement:
Here are some examples of simple statements:
# assignment statement ended by the end-of-line mark >>> x = 10 # 2 statements in 1 line # ";" is used to end the first statement >>> x = 20; del x # 1 statement in 2 lines # "\" is used to escape the end-of-line # "..." is the Python prompt for pending statement >>> x = \ ... 30
2. What Is Compound Statement? A compound statement is a unit of executable code that contains sub-statements.
A compound statement is organized into one or more clauses. Each clause starts with clause header and is followed by a block of indented sub-statements.
clause_header: sub-statement sub-statement ... clause_header: sub-statement sub-statement ... ...
For example, the "if" statement is a compound statement with multiple clauses.
if condition: sub-statement sub-statement ... elif condition: sub-statement sub-statement ... ... else: sub-statement sub-statement ...
Table of Contents
Variables, Operations and Expressions
"pass" Statement - Do Nothing Statement
Expression Statement - One Expression Only
"=" Statement - Assignment Statement
"del" Statement - Delete Statement
"import" Statement to Load Modules
"if" Statement for Conditional Execution
"while" Statement for Execution Loop
"for" Statement for Iterative Execution
"try" Statement to Catch Execution
"with" Statement for Context Manager
"match" Statement for Pattern Match
Function Statement and Function Call
Iterators, Generators and List Comprehensions
Packages and Package Directories
"pathlib" - Object-Oriented Filesystem Paths
"pip" - Package Installer for Python
SciPy.org - Python Libraries for Science
pandas - Data Analysis and Manipulation
Anaconda - Python Environment Manager