What does target and object mean in assignment statements?

88 Views Asked by At

https://docs.python.org/3/library/copy.html#module-copy

Assignment statements in Python do not copy objects, they create bindings between a target and an object. For collections that are mutable or contain mutable items, a copy is sometimes needed so one can change one copy without changing the other.

If I have the following code:

variable1 = 'a string'

Is variable1 the target and a string the object, or what do these 2 terms refer to?

I don't want to make a specific code or solve anything, just understand the documentation, I am a beginner student in Python.

1

There are 1 best solutions below

4
RandomCoder368 On

You are correct, the target is a variable, and a value is the object. A target is binded to a variable. For extra context, the copy module creates a new object so you can change one without affecting another.