Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Saving variables in memory
#5
(Mar-08-2021, 06:37 PM)snippsat Wrote:
(Mar-08-2021, 03:48 PM)pprod Wrote: I understand Python saves variables in memory, right? As it does so, does it create any logs or files with a reference to the content of the variables?
>>> n = 99
>>> id(n)
1966484706736

>>> help(id)
Help on built-in function id in module builtins:

id(obj, /)
    Return the identity of an object.
    
    This is guaranteed to be unique among simultaneously existing objects.
    (CPython uses the object's memory address.)

>>> globals()['n']
99
Variable is stored somewhere in the free memory that's available.
Also stored in global namespace,which is a internal dictionary(globales()) that python use.
>>> a = 'hello world'
>>> b = 'hello world'
>>> a is b
False
>>> a == b
True
is will return True if two variables point to the same object in memory.
== if the objects referred by the variables are equal.
>>> a = 'hello world'
>>> b = a
>>> a is b
True
>>> a == b
True
Other languages have variables Python has names.
So over here is a and b name tagged to same memory address.

Thanks for the insight, snippsat!
Reply


Messages In This Thread
Saving variables in memory - by pprod - Mar-08-2021, 03:48 PM
RE: Saving variables in memory - by deanhystad - Mar-08-2021, 04:36 PM
RE: Saving variables in memory - by pprod - Mar-08-2021, 04:44 PM
RE: Saving variables in memory - by snippsat - Mar-08-2021, 06:37 PM
RE: Saving variables in memory - by pprod - Mar-08-2021, 08:24 PM
RE: Saving variables in memory - by deanhystad - Mar-08-2021, 08:42 PM
RE: Saving variables in memory - by jefsummers - Mar-08-2021, 11:16 PM
RE: Saving variables in memory - by buran - Mar-09-2021, 06:02 AM
RE: Saving variables in memory - by jefsummers - Mar-10-2021, 01:18 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020