Newbie: tuple list confusion.
Q852913745
q852913745 at aol.com
Sun Sep 12 19:55:29 EDT 2004
I am trying to learn python from 'Python programming for the absolute beginner'
I'm sure I understand the difference between tuples and lists, but while
experimenting with what I have learned so far, I was suprised that this code
worked.
# Create list a
a=["start",878,"item 1",564354,"item 2"]
print "length of list a =",len(a)
print "a =",a ; print
# Create tuple b
b=(234,"item 3",456,"end")
print "length of tuple b =",len(b)
print "b =",b ; print
print "Add b onto a" # Shouldn't work!
#---------------------------------------------
# a=a+b # causes an error as it should,
a+=b # but why is this ok?
#---------------------------------------------
print "a =",a
print "length of a =",len(a)
print;c=raw_input("Press enter to exit")
My book states that a=a+b and a+=b are the same, and that different 'types' of
sequence cannot be joined together.
More information about the Python-list
mailing list