20. Unpacking sequences and tuples
The key is to avoid long code that breaks up the coherent intention. In the discouraged approach, we receive a tuple, and store it in s and then for each element in s, use a different line to access the values. In the encouraged approach, the tuple is unpacked neatly into one line.
20.1. Don’t do this
1def get_student(): 2 return 'john', 'doe', 88 3 4s = get_student() 5 6first_name = s 7last_name = s 8score = s 9 10print(first_name, last_name, score)
20.2. Do this
1def get_student(): 2 return 'john', 'doe', 88 3 4first_name, last_name, score = get_student() 5 6print(first_name, last_name, score)