Tuples

Tuples often stay in the shadow of lists. On the surface, they are very similar: they are also 1D arrays, can mix different types, use the same indices, and can be sliced. Similar to lists, tuples can be created using the tuple() function, or by only using parentheses:

breakfast = ('oatmill', 'scrambled eggs', 'orange juice')

There is one major difference that makes tuples work better for some tasks, but less so for others. As we mentioned before, lists are dynamic and can be modified in place. Tuples are not; once built, tuples remain static and cannot be changed (therefore, they don't have append and extend methods). This property is known as immutability.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset