+ 5
Hi Mebatsion 2, The is operator and == are different. == checks if the values of two objects are the same, while is checks if they are actually the same object in memory. For mutable objects like lists, even if they look identical, they are stored in different memory locations, so a == b might be True, but a is b will be False. For immutable objects like integers, small numbers might share the same memory location to save space, so a is b can be True even if they were created separately. However, this can vary between Python versions. For boolean values, there’s only True and False, and these are always the same objects in memory, so a is b and a == b will always give the same result. Example: a = True b = not False print(a is b) # True (always) a = 3 b = 1 + 2 print(a is b) # True (often) a = [1, 2, 3] b = [1, 2, 3] print(a is b) # False (always) a = [1, 2, 3] b = a print(a is b) # True (trivial)
22nd Aug 2024, 3:03 PM
Per Bratthammar
Per Bratthammar - avatar
+ 8
Mebatsion 2 An operator generally does something like add, subtract, multiple, divide whereas a boolean compares liken to the example provided below x = "True" if 24 >= 12 else "False" print(x) # True x = "True" if 12 >= 24 else "False" print(x) #False print(24 >= 12) #True print(12 >= 24) #False
22nd Aug 2024, 1:22 PM
BroFar
BroFar - avatar
+ 3
https://testbook.com/key-differences/difference-between-equality-and-identity-operator-in-JUMP_LINK__&&__python__&&__JUMP_LINK The link above gives clear examples of the difference between values and object ids.
22nd Aug 2024, 3:08 PM
Ruben
+ 2
= operator assigns value to a variable while == operator checks whether two values are equal or not
24th Aug 2024, 8:09 AM
Madhvika
Madhvika - avatar
+ 2
class MyBool: def __init__(self, value): self.value = value def __eq__(self, other): return self.value == other.value obj1 = MyBool(True) obj2 = MyBool(True) print(obj1 == obj2) # True, because values are equal print(obj1 is obj2) # False, because they are different objects
2nd Sep 2024, 12:14 PM
đŸ’„ertdf uiopđŸ’„
đŸ’„ertdf uiopđŸ’„ - avatar
+ 1
What is python
23rd Aug 2024, 8:03 AM
ankit kumar
ankit kumar - avatar
+ 1
Is operator checks for the same thing having the similar attributes or features while the == operator checks for the value of them and returns in a boolean value true if they are or they return false.
24th Aug 2024, 6:20 AM
Aditya Yadav
Aditya Yadav - avatar
+ 1
Hello there,
24th Aug 2024, 11:13 AM
Rohit Lonkar
Rohit Lonkar - avatar
+ 1
Will you write program for student feedback system in python
24th Aug 2024, 11:14 AM
Rohit Lonkar
Rohit Lonkar - avatar
+ 1
Superb
25th Aug 2024, 9:34 AM
Justine mwaba
Justine mwaba - avatar
+ 1
is operator is used for the comparison of qualities(like their features) of two things while == operator is used to check the comparison b/w them
1st Sep 2024, 12:40 PM
neha 2486
neha 2486 - avatar