Lists and Tuples

Lists and tuples are two types of python sequences. They can be sequences of arbitrary objects and can be heterogeneous. The primary difference between tuples and lists is that lists are mutable and tuples are immutable.

[code lang=”python”]

#lists and tuples

a = [ “John”, “Foster”, “Dulles” ]

print a

a[0] = “David”
a[2] = “Wallace”

print a

b = ( “MK”, “Ultra” )

a = a + list(b)

print a

c = [ [”John”, “David”], “Foster”, [”Wallace”, “Dulles”] ]

print c[0][0] + c[1] + c[2][0]

[/code]

Leave a Reply