Skip to content

Instantly share code, notes, and snippets.

@tomotaka
Created August 21, 2013 07:35
Show Gist options
  • Save tomotaka/6291350 to your computer and use it in GitHub Desktop.
Save tomotaka/6291350 to your computer and use it in GitHub Desktop.
appendと+の違い
import pprint
print '----try not append----'
a = []
print 'object id of variable \'a\' => %d' % id(a)
print 'content of variable \'a\': %s' % pprint.pformat(a)
a = a + [1]
print 'added value 1 with + operator'
print 'object id of variable \'a\' has changed: %d' % id(a)
print 'content of variable \'a\': %s' % pprint.pformat(a)
print '----try append----'
b = []
print 'object id of variable \'b\' => %d' % id(a)
print 'content of variable \'b\': %s' % pprint.pformat(b)
b.append(2)
print 'added value 2 with append() method'
print 'object id of variable \'b\' has not changed: %d' % id(a)
print 'content of variable \'b\': %s' % pprint.pformat(b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment