Python Forum
Question regarding local and global variables - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Question regarding local and global variables (/thread-25818.html)

Pages: 1 2


RE: Question regarding local and global variables - buran - Apr-12-2020

(Apr-12-2020, 03:06 PM)TomToad Wrote: But curiously, the ids are overwritten as well which seems to contradict the documentation.
No, it does not contradict the docs, it's the id of the object at which the name points.


RE: Question regarding local and global variables - buran - Apr-12-2020

(Apr-12-2020, 03:09 PM)donmerch Wrote: It just stood out to me why one type of object (integer, list) is referred to differently inside and outside a function.
First of all, int and list are different types. There is difference because lists are mutable. Same will apply to other mutable objects like dict.
However, when it comes to assignment, it's not different (your first snippet). You must make distinction when you assign to name c and when you change element INSIDE mutable object (i.e. c[0])


RE: Question regarding local and global variables - TomToad - Apr-12-2020

(Apr-12-2020, 03:11 PM)buran Wrote: No, it does not contradict the docs, it's the id of the object at which the name points.
Yes, it does contradict. According to the docs from here, the id is guaranteed to be constant throught the life of the object.
I would not consider a value that changes to be constant.

Scratch that, sometimes I forget that Python handles objects and types differently from what I'm use to.