As we mentioned earlier, in Python Programming strings and lists are both examples of sequences. Strings are sequences of characters, and are immutable. Lists are sequences of elements of any data type, and are mutable. The third sequence type is the tuple. Tuples are like lists, since they can contain elements of any data type. But unlike lists, tuples are immutable. They’re specified using parentheses instead of square brackets.
You might be wondering why tuples are a thing, given how similar they are to lists. Tuples can be useful when we need to ensure that an element is in a certain position and will not change. Since lists are mutable, the order of the elements can be changed on us. Since the order of the elements in a tuple can't be changed, the position of the element in a tuple can have meaning. A good example of this is when a function returns multiple values. In this case, what gets returned is a tuple, with the return values as elements in the tuple. The order of the returned values is important, and a tuple ensures that the order isn’t going to change. Storing the elements of a tuple in separate variables is called unpacking. This allows you to take multiple returned values from a function and store each value in its own variable.
In questa pagina del sito puoi guardare il video online 42 Lists and Tuples | Python [ COMPLETE COURSE ] della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Tech Lab 19 agosto 2020, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 11 volte e gli è piaciuto 1 spettatori. Buona visione!