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

 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

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

 Function Statement and Function Call

 Iterators, Generators and List 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