Created
August 21, 2013 07:35
-
-
Save tomotaka/6291350 to your computer and use it in GitHub Desktop.
appendと+の違い
This file contains 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
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