**Python Tutorials - Herong's Tutorial Examples** - v2.15, by Herong Yang

What Is Expression

This section provides a quick introduction of expressions. An expression is a sequence of lexical tokens in Python source code that expresses a single object, a single operation, or multiple operations executed sequentially.

**What Is Expression?**
An expression is a sequence of lexical tokens in Python source code
that expresses a single object, a single operation,
or multiple operations executed sequentially.

An expression will always produce an object at the end.

When an expression with multiple operations is executed, the order of execution follow 3 generic rules:

- Operations enclosed within parentheses are executed first.
- Operations with higher precedences are executed first.
- Operations on the left are executed first, if they have the same precedence.

The table below lists some commonly used operations on numeric and Boolean objects. They are sorted by their precedences in descending order.

Symbols Operations -------------------- -------------- (...) Parentheses ** Exponentiation *, /, //, % Multiplication and divisions +, - Addition and subtraction <, <=, >, >=, ==, != Comparisons not Boolean NOT and Boolean AND or Boolean OR

Here are some examples of expressions:

# expression with a single "int" object >>> 9 9 # expression with a single "tulip" object >>> (9, 1, 1) (9, 1, 1) # expression with a single operation >>> 9 + 3 12 # expression with two operations # multiplication has higher precedence and gets executed first >>> 9 + 3 * 2 15 # expression with a single operation # addition within parentheses gets executed first >>> (9 + 3) * 2 24 # expression with multiple operations in different data types >>> (9 + 3) * 2 < 10 or (9 + 3) * 2 > 20 True # expression with objects referred by variables >>> x = (9 + 3) * 2 >>> x < 10 or x > 20 True

Precedences of other operations will be discussed for each specific group of data types.

Table of Contents

►Variables, Operations and Expressions

Conditional Expression - Ternary Operation

Assignment Expression - Walrus Operation

Function Statement and Function Call

List, Set and Dictionary 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