Suppose we have the following Tuple:
("red", "blue", "green", "yellow")
We want to extract only red
and green
and yellow
. How would we do that? Python gives the ability to extract the elements that we want while ignoring other elements.
danger, _, safe, warning = ("red", "blue", "green", "yellow")
print(danger, safe, warning, sep="\n")
The output will be as follows:
red
green
We can do the same thing with lists and get the same output:
danger, _, safe, warning = ["red", "blue", "green", "yellow"]
print(danger, safe, warning, sep="\n")
The output will be as follows:
red
green