Computer Science
Are these values equal? Why/why not?
- 20 and 20.0
- 20 and int(20)
- str(20) and str(20.0)
- 'a' and "a"
Python Data Handling
47 Likes
Answer
- The type of 20 is int whereas the type of 20.0 is float so they are two different objects. Both have the same value of 20. So, as values are same equality (==) operator return True but as objects are different is operator returns False.
- The value and type of both 20 and int(20) are the same and both point to the same object so both equality (==) and is operator returns True.
- For str(20) and str(20.0), both equality (==) and is operator returns False as their values are different and they point to two different objects.
- For 'a' and "a", both equality (==) and is operator returns True as their values are same and they point to the same object.
Answered By
19 Likes
Related Questions
Is it true that if two objects return True for is operator, they will also return True for == operator?
What is an atom in Python? What is an expression?
What is the difference between implicit type conversion and explicit type conversion?
What are three internal key-attributes of a value-variable in Python ? Explain with example.