How Operators Treat the Variables?

Learn the comparison among =, ==, and is operator in Python.

This section addresses two common questions, and coding without knowing the answers to them is like skating on thin ice. Without any further delay, let’s explore them together.

Holding references or copies

We must know the difference between holding a reference to an item and holding a copy of an item. For example, if we have two variables x and y:

x = [1, 2, 3]
y = x

The line y = x means that y holds the reference to the same list as x. Tweaking x as:

x.append(4)

will also affect the variable y. Run the following program to witness this change.

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy