Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save arturotena/04737fcefd44b101a924b07342cfe451 to your computer and use it in GitHub Desktop.

Select an option

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. +=)
# 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