Compound Types

The variables we have seen so far represent one single item each. If x is a floating-point number, it takes on one value at a time. Compound types are those for which a single variable represents many elements. In Python, compound types can be sequences, which can be ordered by integer indexes. We will focus on sequences here, since they are very widely used. A few compound types are unordered, such as dictionaries and sets; we will study those later.


In Python types are categorized as mutable or immutable. Immutable types cannot be changed in place, but they can be overwritten.


All the types we have seen so far are immutable. Compound types may be mutable; their elements can be changed in place. Compound types may also be immutable. Strings are a compound type but they are immutable.

S1="Hello world"
S1[0:5]="Goodbye" #illegal
S1="Goodbye cruel world." #legal