In Python "==" operator returns true if: --------------------------------------…
2024
In Python "==" operator returns true if:
----------------------------------------
पायथन में "==" ऑपरेटर सत्य देता है यदि :
- A.
Variables are aliases for same object / वेरिएबल एक ही ऑब्जेक्ट के उपनाम हैं
- B.
Content of two different objects are same / दो भिन्न ऑब्जेक्ट्स के कंटेंट समान हैं
- C.
Options (1) & (2) are correct / विकल्प (1) व (2) सही हैं
- D.
All options are wrong / सभी विकल्प गलत हैं
Attempted by 969 students.
Show answer & explanation
Correct answer: C
In Python, the '==' operator is used to compare the values of two objects. It returns True if the values are equal, regardless of whether the objects are the same instance in memory or different instances with the same content.
1. If variables are aliases for the same object, '==' returns True because they refer to the same data. 2. If two different objects have the same content (value), '==' also returns True.
Therefore, both conditions described in options A and B are valid scenarios where '==' returns true. This makes option C the correct choice.
हिन्दी उत्तर:
पायथन में '==' ऑपरेटर दो ऑब्जेक्ट्स के मानों की तुलना करने के लिए उपयोग किया जाता है। यह तब True लौटाता है जब मान समान होते हैं, चाहे ऑब्जेक्ट्स मेमोरी में एक ही हों या अलग-अलग हों लेकिन समान डेटा रखते हों।
1. यदि वेरिएबल एक ही ऑब्जेक्ट के उपनाम (aliases) हैं, तो '==' True लौटाता है। 2. यदि दो अलग-अलग ऑब्जेक्ट्स का कंटेंट समान है, तो '==' भी True लौटाता है।
चूंकि विकल्प A और B दोनों सही स्थितियां हैं, इसलिए विकल्प C (विकल्प 1 और 2 सही हैं) सही उत्तर है।