Identity Operators in Python
เคฏे เคเคชเคฐेเคเคฐ्เคธ เคเคฌ्เคेเค्เค्เคธ เคी เคเคเคกेंเคिเคी (เคฎेเคฎोเคฐी เคเคก्เคฐेเคธ) เคो เคेเค เคเคฐเคคे เคนैं เคเคฐ เคธเคฎाเคจ เคนोเคจे เคฏा เคจ เคนोเคจे เคे เคเคงाเคฐ เคชเคฐ True เคฏा False เคฎें เคชเคฐिเคฃाเคฎ เคฆेเคคे เคนैं। เคชाเคฏเคฅเคจ เคฎें, เคเคเคกेंเคिเคी เคเคชเคฐेเคเคฐों เคा เคเคชเคฏोเค เคฏเคน เคจिเคฐ्เคงाเคฐिเคค เคเคฐเคจे เคे เคฒिเค เคिเคฏा เคाเคคा เคนै เคि เค्เคฏा เคฆो เคตेเคฐिเคเคฌเคฒ เคฏा เคเคฌ्เคेเค्เค เคเค เคนी เคฎेเคฎोเคฐी เคธ्เคฅाเคจ เคो เคธंเคฆเคฐ्เคญिเคค (เคฆเคฐ्เคถाเคคे) เคเคฐเคคे เคนैं เคฏा เคเค เคนी เคชเคนเคाเคจ เคฐเคเคคे เคนैं।
เคเคเคกेंเคिเคी เคเคชเคฐेเคเคฐों เคा เคเคชเคฏोเค เค เค्เคธเคฐ เคเคฌ्เคेเค्เค เคी เคคुเคฒเคจा เคเคฐเคจे เคเคฐ เคฏเคน เคांเคเคจे เคे เคฒिเค เคिเคฏा เคाเคคा เคนै เคि เค्เคฏा เคตे เคเค เคนी เคเคฆाเคนเคฐเคฃ เคนैं, เคाเคธเคเคฐ เคเคฌ เคฒिเคธ्เค, เคกिเค्เคถเคจเคฐी เคเคฐ เคฏूเคเคฐ-เคกिเคซाเคंเคก เค्เคฒाเคธेเค เคैเคธी เคชเคฐिเคตเคฐ्เคคเคจเคถीเคฒ เคเคฌ्เคेเค्เค เคธे เคจिเคชเคเคคे เคนैं। เคง्เคฏाเคจ เคฐเคें เคि เคฏे เคเคชเคฐेเคเคฐ เคชเคนเคाเคจ เคी เคाँเค เคเคฐเคคे เคนैं, เคธเคฎाเคจเคคा เคी เคจเคนीं। เคฆो เคเคฌ्เคेเค्เค เคฎूเคฒ्เคฏ เคฎें เคธเคฎाเคจ เคนो เคธเคเคคी เคนैं เคฒेเคिเคจ เคเคจเคी เคชเคนเคाเคจ เคธเคฎाเคจ เคจเคนीं เคนो เคธเคเคคी।
These operators check the identity (memory address) of the objects and return True or False depending on whether they are equal or not. In Python, identity operators are used to determine if two variables or objects reference the same memory location or have the same identity.
Identity operators are often used to compare objects and check if they are the same instance, especially when dealing with mutable objects like lists, dictionaries, and user-defined classes. Keep in mind that these operators check for identity, not equality. Two objects can be equal in value but not have the same identity.
-
Is Identitical ( is )
- Is Not Identitical ( is not )
Is Identical (is):-
เคฏे เคเคชเคฐेเคเคฐ เคฆो เคเคฌ्เคेเค्เค เคे identity เคฏाเคจि object reference (เคฎेเคฎोเคฐी เคเคก्เคฐेเคธ) เคे เคธเคฎाเคจ เคนोเคจे เคชเคฐ True เคฆेเคคा เคนै เค เคจ्เคฏเคฅा False เคฆेเคคा เคนै। เคชाเคฏเคฅเคจ เคฎें, "is" เคเคชเคฐेเคเคฐ เคा เคเคชเคฏोเค เคฏเคน เคชเคฐीเค्เคทเคฃ เคเคฐเคจे เคे เคฒिเค เคिเคฏा เคाเคคा เคนै เคि เค्เคฏा เคฆो เคตेเคฐिเคเคฌเคฒ เคฏा เคเคฌ्เคेเค्เค เคเค เคนी เคฎेเคฎोเคฐी เคธ्เคฅाเคจ เคฏा เคฎेเคฎोเคฐी เคฎें เคเค เคนी เคเคฌ्เคेเค्เค เคो เคธंเคฆเคฐ्เคญिเคค (เคฆเคฐ्เคถाเคคे) เคเคฐเคคे เคนैं। เคฏเคน เคเคฌ्เคेเค्เค เคी เคชเคนเคाเคจ เคी เคाँเค เคเคฐเคคा เคนै, เคจ เคि เคेเคตเคฒ เคฎूเคฒ्เคฏों เคी เคธเคฎाเคจเคคा เคी।
เคเคฌ เคเคช "is" เคเคชเคฐेเคเคฐ เคा เคเคชเคฏोเค เคเคฐเคคे เคนैं, เคคो เคฏเคน เคाँเคเคคा เคนै เคि เค्เคฏा เคฆो เคตेเคฐिเคเคฌเคฒ เคฎेเคฎोเคฐी เคฎें เคเค เคนी เคเคฌ्เคेเค्เค เคो เคธंเคฆเคฐ्เคญिเคค เคเคฐเคคे เคนैं। เคฏเคฆि เคตे เคเคธा เคเคฐเคคे เคนैं, เคคो เคฏเคน 'True' เคฒौเคाเคคा เคนै; เค เคจ्เคฏเคฅा, เคฏเคน 'False' เคฒौเคाเคคा เคนै। "is" เคเคชเคฐेเคเคฐ เคे เคตिเคชเคฐीเคค, เคเคช "==" เคเคชเคฐेเคเคฐ เคा เคเคชเคฏोเค เคฏเคน เคांเคเคจे เคे เคฒिเค เคเคฐ เคธเคเคคे เคนैं เคि เค्เคฏा เคฆो เคตेเคฐिเคเคฌเคฒ เคे เคธเคฎाเคจ เคฎाเคจ เคนैं, เคญเคฒे เคนी เคตे เคฎेเคฎोเคฐी เคฎें เคเค เคนी เคเคฌ्เคेเค्เค เคो เคธंเคฆเคฐ्เคญिเคค เคเคฐเคคे เคนों।
เคเคช เคเคฎเคคौเคฐ เคชเคฐ เคจिเคฎ्เคจเคฒिเคिเคค เคธ्เคฅिเคคिเคฏों เคฎें `is` เคเคชเคฐेเคเคฐ เคा เคเคชเคฏोเค เคเคฐเคคे เคนैं:
- None เคธे เคคुเคฒเคจा:
- เคเคฌ्เคेเค्เค्เคธ เคी เคคुเคฒเคจा เคเคฐเคจा:
- เคตिเคถिเคท्เค เคांเคธ्เคेंเค เคी เคाँเค เคเคฐเคจा:
This operator returns True if the identity of two objects i.e. object reference (memory address) is same, otherwise it returns False. In Python, the "is" operator is used to test whether two variables or objects reference the same memory location or the same object in memory. It checks for object identity, not just equality of values.
When you use the "is" operator, it checks if two variables reference the same object in memory. If they do, it returns `True`; otherwise, it returns `False`. In contrast to the "is" operator, you can use the "==" operator to test whether two variables have the same values, regardless of whether they reference the same object in memory.
You typically use the `is` operator in the following situations:
- Comparing None:
- Comparing Objects:
- Checking for Specific Constants:
a=1
b=1
Is Not Identical (is not):-
เคฏे เคเคชเคฐेเคเคฐ เคฆो เคเคฌ्เคेเค्เค เคे identity เคฏाเคจि object reference (เคฎेเคฎोเคฐी เคเคก्เคฐेเคธ) เคे เคธเคฎाเคจ เคจ เคนोเคจे เคชเคฐ True เคฆेเคคा เคนै เค เคจ्เคฏเคฅा False เคฆेเคคा เคนै। เคชाเคฏเคฅเคจ เคฎें, 'is not' เคเคชเคฐेเคเคฐ เคเค เคคुเคฒเคจा เคเคชเคฐेเคเคฐ เคนै เคिเคธเคा เคเคชเคฏोเค เคฏเคน เคांเคเคจे เคे เคฒिเค เคिเคฏा เคाเคคा เคนै เคि เค्เคฏा เคฆो เคตेเคฐिเคเคฌเคฒ เคฏा เคเคฌ्เคेเค्เค เคเค เคนी เคฎेเคฎोเคฐी เคธ्เคฅाเคจ เคो เคธंเคฆเคฐ्เคญिเคค เคจเคนीं เคเคฐเคคे เคนैं। เคฏเคน `is` เคเคชเคฐेเคเคฐ เคा เคจिเคทेเคง เคนै। `x is not y` เคฒौเคाเคคा เคนै `True` เคฏเคฆि `x` เคเคฐ `y` เคฎेเคฎोเคฐी เคฎें เคเค เคนी เคเคฌ्เคेเค्เค เคो เคธंเคฆเคฐ्เคญिเคค เคจเคนीं เคเคฐเคคे เคนैं, เคเคฐ เคฏเคฆि เคตे เคเค เคนी เคเคฌ्เคेเค्เค เคो เคธंเคฆเคฐ्เคญिเคค เคเคฐเคคे เคนैं เคคो `False` เคฆेเคคा เคนै।
This operator returns True if the identity of two objects i.e. object reference (memory address) is not the same, otherwise it returns False. In Python, the `is not` operator is a comparison operator used to check if two variables or objects do not refer to the same memory location. It is the negation of the `is` operator. `x is not y` returns `True` if `x` and `y` do not reference the same object in memory, and `False` if they do reference the same object.
b=2
Comments
Post a Comment