Python Tutorials - Herong's Tutorial Examples
∟Statements - Execution Units
This chapter provides introductions and tutorial examples about statements. Topics include introductions to expression, assignment, 'del', 'import', 'if', 'while', 'for', 'try', 'with', and 'match' statements.
What Is Statement
"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
Takeaways:
- A statement is a smallest unit of code
that can be sent to the Python system to execute.
- A "null" statement does nothing and
is commonly used used as a placeholder to form an empty sub-statement block.
- An expression statement evaluates a single expression.
- A "=", or assignment, statement
assigns objects to reference targets.
- A "del", or delete, statement
deletes the definitions of given targets and their associated object references.
- An "if" statement
selects a block of sub-statements to execute based on given conditions.
- A "while" statement
executes a block of sub-statements repeatedly while the given
condition is valid.
- A "for" statement
iterates over the elements of a sequence and executes a block of sub-statements
for each iteration.
- A "try" statement
allows you to manage exceptions raised from a block of sub-statements.
- A "with" statement
wraps a standard "try" statement with a context manager object.
- A "match" statement
selects a block of sub-statements to execute based on pattern match algorithms.
Table of Contents
About This Book
Running Python Code Online
Python on macOS Computers
Python on Linux Computers
Built-in Data Types
Variables, Operations and Expressions
►Statements - Execution Units
Function Statement and Function Call
Iterators and Generators
List, Set and Dictionary Comprehensions
Classes and Instances
Modules and Module Files
Packages and Package Directories
"sys" and "os" Modules
"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
Jupyter Notebook and JupyterLab
References
Full Version in PDF/EPUB