2. Ignoring unpacked values from a tuple

Avoid creating an extra variable when unpacking tuples. Use _ for a value you intend to ignore.

Using _ signals to readers that the value exists but is intentionally irrelevant here. That makes the unpacking contract clear without inventing a meaningless variable name that suggests the value matters.

2.1. Don’t do this

1def get_info():
2    return 'John', 'Doe', 28
3
4fname, lname, tmp = get_info()
5
6print(fname, lname)

2.2. Do this

1def get_info():
2    return 'John', 'Doe', 28
3
4fname, lname, _ = get_info()
5
6print(fname, lname)