Learning Python: Part 1: Creating and Using Variables

Learning Python

Python is a general-purpose interpreted programming language. It emphasizes readability through the use of whitespace and supports multiple programming paradigms such as functional and object-oriented models.

Creating and Using Variables

Understanding how it uses variables is fundamental to learning a new programming language. Each handles them in a slightly different way and have their own rules for the two main tasks associated with them: creating and using them.

Creating Variables

Variables are created in Python through naming them. As a loosely-typed language, variables act as buckets that can hold any type of data such as those like whole numbers, combinations of letters and numbers enclosed in quotation marks (strings), and fractional number (integers).

Through defining them, data is “put” into the bucket that is the variable. Through using that name again later in the code, the value associated with it can be retrieved.

Using Variables

To use a variable, its name is used in place of the value it “holds.” This means that complex operations can be divided and parts of calculations can be saved between steps.

The result of an operation like addition (+), subtraction (-), multiplication (*), or division (/) is saved in the variable on the left-side of the statement.


A line of code in Python is known as a statement. It “states” something. It begins with variables and some combination of operations or other expressions and ends with empty space.

Unlike some other programming languages, a statement ends in Python when there is no more code on that line but whitespace. In many ways, then, code in Python can be thought of appearing line-by-line with each line being some new statement.

In the case of some mathematical operation, the result is saved to the left. This is known as an assignment statement. Some value is “assigned” to a variable on the left side of the equal sign (=).

Statements that do not “state” something are known as expression statements. They “express” something instead of “assigning” data into a variable. These include operations that do not save the value or are used to display data in some way.

Play with the example on Repl.it!