Destination in python

I know that "assigning a variable" in python is actually binding / re-binding the name (variable) to the object.

The question arises: is it possible to have the correct assignment in python, for example, to make an object equal to another object?

I assume python is not necessary:

  • Prohibited objects cannot be assigned because they cannot be changed

  • Mutable objects can be assigned because they can be changed, and this can be useful since you can manipulate a copy of the dictionary separately from the original. However, in these cases, the python philosophy offers a cloning method on a mutable object, so you can bind a copy, not the original.

So, I think the answer is that in python there is no purpose, the best way to mimic it is to bind to the cloned object

I just wanted to share this question if I missed something important here.

thank

EDIT:

The answers of Lee Ryan and Sven Marnach are good, I think the common answer is a combination of both:

For custom types, use the idiom:

a. dict = dict (b. dict )

(I assume this also has problems if the assigned class has redefined attribute access methods, but not scary :))

For volatile built-in modules (lists and dictations), the cloning / copying methods they provide (e.g. snippets, updating) are used

final built-in plug-ins cannot be changed, therefore they cannot be assigned

, , .

!

+3
3

: python, , ?

, :

a.__dict__ = dict(b.__dict__)

C/++ (.. ).

, . ++ , , , .

+3

, Python - .

"-" Python () :

l = [2, 3]
m = list(l)
l is m
--> False

[ . , " " ( ++) Python - - . , .]

y = type(x)(x), . , , copy, .

Python . , :

l = [2, 3]
m = l
l[:] = [3, 4, 5]
m
--> [3, 4, 5]

clear(), update(otherdict), . s

s.clear()
s |= otherset
+4

I donโ€™t think you are missing something.

I like to portray variables in python as a name written in โ€œshortcutsโ€ that attaches to boxes, but can change its location as intended, whereas in other languages โ€‹โ€‹the destination changes the contents of the window (and the assignment operator may be overloaded).

Beginners can write quite complex applications without knowing it, but usually these are dirty programs.

+1
source

Source: https://habr.com/ru/post/1775405/


All Articles