The function id () in Python

The built-in function id () in Python returns a single integer value that identifies an object.

The built-in function id () in Python returns a single integer value that identifies an object.

  1. All objects in Python have their own unique id .
  2. Id is assigned to the object when it is created.

Id () function syntax

 id(object) 

Parameters of the id function ()

Id () has a unique parameter:

  1. object : is an object, number, string, list, class . that must return id.

Value returned from id ()

The id () function returns the identity of the object. This is a unique integer for the injected object and remains constant throughout its life cycle.

For example

1. The way id () works in Python

 class Demo: b = 5 qtmDemo = Demo() print('id của qtmDemo =',id(qtmDemo)) 

Run the program, the result will be in the form:

 id của qtmDemo = 139870602688104 

2. Some other examples:

 print('id của 5 =',id(5)) a = 5 print('id của a =',id(a)) b = a print('id của b =',id(b)) c = 5.0 print('id của c =',id(c)) 

Result:

 id của 5 = 10914496 id của a = 10914496 id của b = 10914496 id của c = 139870675422424 

See also: Built-in Python functions

Update 17 June 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile