What Is Variable

This section provides a quick introduction variables. A variable in Python is a symbolic name of a data object.

What Is Variable? A variable in Python is a symbolic name of a data object. Or you can say that a variable is an object name.

There several important features about Python variables.

1. An object can have 0, 1, or many names.

# create an object with no name assigned
>>> 'apple'
'apple'

# create an object and assign a name "x"
>>> x = 'apple'

# assign the object named "x" with another name "y"
>>> y = x

2. A variable can also be considered as an storage for a reference or a pointer to the object.

# create an object with no reference stored
>>> 'apple'
'apple'

# create an object with reference stored in "x"
>>> x = 'apple'

# copy the reference in "x" to "y"
>>> y = x

3. Its object value is used, when a variable is being operated.

# variable "x" is referring to "int" object for integer 3
>>> x = 3

# object's value 3 is being operated: 3*3
>>> x*x
9

4. a variable must be assigned (defined) with an object, before using it in operations.

# variable "y" has not been assigned with any object
>>> y*y
NameError: name 'y' is not defined

5. Variable names are case sensitive.

# 'x' and 'X' are 2 different variables
>>> x = 3
>>> X*X
NameError: name 'X' is not defined

6. A variable can be reassigned to another object of any data type at any time.

# create a "str" object and assign a name "x"
>>> x = 'apple'

# "x" is reassigned to another object
>>> x = [9, 1, 1]

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 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