Tuples

The final built-in data type is the tuple. Python tuples work exactly like Python lists except they are immutable; that is, they can't be changed in place. They are normally written inside parentheses to distinguish them from lists (which use square brackets), but as you'll see, parentheses aren't always necessary; however, a comma is always required, as expressions can use parentheses too. Since tuples are immutable, their length is fixed. To grow or shrink a tuple, a new tuple must be created.

Since parentheses can surround expressions, you have to show Python when a single item is actually a tuple by placing a comma after the item. A tuple without parentheses can be used when a tuple is unambiguous. However, it's easier to just use parentheses than to screenshot out when they're optional.

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

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