Python Forum

Full Version: Question regarding local and global variables
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(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.
(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])
(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.
Pages: 1 2