Created
October 3, 2025 18:22
-
-
Save arturotena/04737fcefd44b101a924b07342cfe451 to your computer and use it in GitHub Desktop.
Immutable Python classes can create a new instance on augment operations (e.g. +=)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Class decimal.Decimal augment operations creates a new object, because it is immutable. | |
| import decimal | |
| a = decimal.Decimal('42') | |
| b = decimal.Decimal('41') | |
| b += decimal.Decimal('1') | |
| print(a) # 42 | |
| print(b) # 42 | |
| print(a == b) # True | |
| print(a is b) # False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment