Should datetime objects be deeply copied?

So, I noticed another week, having done an experiment, which, although it was a high-level language, while you can make copies of variables by simply assigning them as follows:

a = 5    
b = a
print(b) # 5
b = 3
print(b) # 3
print(a) # 5

... if you process the dictionaries or perhaps the lists the same way, it disappears! Another time, I created an error in my code, thinking that dictionaries work the same way. We found out that for a correct, deep copy you need to go:

b = dict(a)

Anyway, I'm busy with datetime objects, and I manipulate them as if they were integers, now it starts to get a little nervous about whether everything is okay. Does all this seem a little arbitrary where it works and where not, do I need to run an experiment every time to check its behavior? It can be assumed that strings probably work as integers, but are not sure where the behavior changes.

I can see that someone asked about this for PHP, but for Python I tend to think that any datetime object assignment would be a correct, deep copy and never mess by accident with the original variable. Does anyone know for sure?

+6
source share
2

datetime ( )

.

.

datetime , , .

, , PM 2Ring, , . , .

+7

.

Python . .

, , , .

, , , , . , , , , , . , dict datetime, , .

+5

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


All Articles