1. Unpacking sequences and tuples

Avoid stretching simple unpacking across multiple lines. In the first approach, a tuple is stored and then indexed repeatedly. In the second, the tuple is unpacked directly in one line.

Direct unpacking states the expected shape of the returned data at the point of use. That usually reads better than treating the tuple as a tiny anonymous container and indexing into it repeatedly.

1.1. Don’t do this

 1def get_student():
 2    return 'john', 'doe', 88
 3
 4s = get_student()
 5
 6first_name = s[0]
 7last_name = s[1]
 8score = s[2]
 9
10print(first_name, last_name, score)

1.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)