Blackthorn

Mutable Variables ( Alias vs Copy )

Mar 10th, 2013
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. >>> hand = dealHand(5)
  2. >>> hand
  3. {'a': 1, 'x': 1, 'l': 1, 'd': 1, 'p': 1}
  4. >>> handClone = hand.copy()
  5. >>> handAlias = hand
  6. >>> handAlias
  7. {'a': 1, 'x': 1, 'l': 1, 'd': 1, 'p': 1}
  8. >>> handAlias is hand
  9. True
  10. >>> handClone is hand
  11. False
  12. >>> hand == handAlias == handClone
  13. True
  14. >>> hand
  15. {'a': 1, 'x': 1, 'l': 1, 'd': 1, 'p': 1}
  16. >>> handAlias.clear()
  17. >>> hand == handAlias == handClone
  18. False
  19. >>> hand
  20. {}
  21. >>> handAlias
  22. {}
  23. >>> handClone
  24. {'a': 1, 'x': 1, 'l': 1, 'p': 1, 'd': 1}
Advertisement
Add Comment
Please, Sign In to add comment