What Is Operation

This section provides a quick introduction operations. An operation is a sequence of lexical tokens in Python source code that invokes a predefined action on one or two data objects.

What Is Operation? An operation is a sequence of lexical tokens in Python source code that invokes a predefined action on one or two data objects.

A typical operation has 3 components which are written in this syntax:

operand_1 operator operand_2

where:
  operand_1 is the first object involved in this operation
  operand_2 is the second object involved in this operation
  operator is the symbolic name of this operation

Notes on the above operation syntax:

1. The action of the operation is determined based on the operand object type and the operator symbolic name. For example:

# an "add" operation generating a new "int" object
# by adding two "int" objects
>>> 10 + 5
15

# a "concatenation" operation generating a new "str" object
# by concatenating two "str" objects
>>> "pine" + "apple"
'pineapple'

2. If an operation only requires one operand object, it is called a unary operation, which is written in this syntax:

operator operand

where:
  operand is the object involved in this operation
  operator is the symbolic name of this operation

For example:

>>> x = 9.8
# "-" is the negation operator on "float" objects
>>> - x
-9.8

# "not" is the NOT operator on "bool" objects
>>> not True
False

# "~" is the Bitwise NOT operator  on "int" objects
>>> ~ 10
-11

3. Whitespaces between operator and operands are optional. For example:

>>> 10 + 5
15

>>> 10+ 5
15

>>> 10     +5
15

To know what operations are supported for a given data type, you need to read the data type reference document. Visit "Built-in Types" document Website at https://docs.python.org/3/library/stdtypes.html to see all operations supported for each built-in data type.

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

 What Is Variable

What Is Operation

 What Is Expression

 Conditional Expression - Ternary Operation

 Assignment Expression - Walrus Operation

 Statements - Execution Units

 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