How to Use id() Function in PythonPython Basics


The id() function is used to get the address of an object in memory.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

a=1
print("the memory address of a is ", id(a))

b=12
print("the memory address of a is ", id(b))

c=101
print("the memory address of a is ", id(c))

Output:

the memory address of a is  1574749872
the memory address of a is  1574750224
the memory address of a is  1574753072

Syntax

id([object])

Parameters

Name Description
object The object name.

Return Value

It returns the memory address of an object.

© 2024 Learnwithgpt.org, all rights reserved. Privacy Policy | Contact Us