Important Notice:

Identity Operators

Identity Operators

24 views 2 min read

Identity Operators (पहचान ऑपरेटर) :-

Identity Operators (पहचान ऑपरेटर) वे Operators हैं जिनका उपयोग यह जाँचने के लिए किया जाता है कि दो variables एक ही object (वस्तु) को refer (संदर्भित) कर रहे हैं या नहीं।

Python में Identity Operators object की identity को compare करते हैं, केवल उनकी value को नहीं।

Identity Operators का result हमेशा Boolean value (True या False) होता है।

English

Identity Operators are used to check whether two variables refer to the same object in memory or not.

They compare the identity of objects, not simply their values.

Identity Operators always return a Boolean value (True or False).

Types of Identity Operators

Python में मुख्य रूप से 2 Identity Operators होते हैं:

  1. is Operator
  2. is not Operator

1. is Operator – एक ही Object है

The is operator checks whether two variables refer to the same object.

is Operator यह जाँचता है कि दो variables एक ही object को refer कर रहे हैं या नहीं।

यदि दोनों variables एक ही object को refer करते हैं, तो result True होता है।

अन्यथा result False होता है।

Syntax:-
 
variable1 is variable2
 
Example:-
 
a = [10, 20, 30]
b = a
print(a is b)
 
Output:-
True
 
Explanation:-

यहाँ:
b = a
का अर्थ है कि b उसी list object को refer करता है जिसे a refer कर रहा है।
इसलिए:
a is b
का result True है।
 
2. is not Operator – एक ही Object नहीं है

The is not operator checks whether two variables do not refer to the same object.

is not Operator यह जाँचता है कि दो variables एक ही object को refer नहीं करते हैं।

यदि दोनों variables अलग-अलग objects को refer करते हैं, तो result True होता है।

 Syntax:-

variable1 is not variable2
 
Example:-
 
a = [10, 20, 30]
b = [10, 20, 30]
print(a is not b)
 
Output:-
True
 
Explanation:-

दोनों lists की values समान हैं:
[10, 20, 30]
लेकिन दोनों अलग-अलग objects हैं।इसलिए:
a is not b
का result True है।

Related Notes