Choosing the first item from a Python tuple

Is there a way to pull the first element from a Python tuple?

For example, for

tuple('A', 'B', 'C')

I would like to pop out "A" and get a tuple containing "B" and "C".

Since tuples are immutable, I understand that I need to copy them to a new tuple. But how can I filter out only the first element of a tuple?

+4
source share
1 answer

With this tuple

x = ('A','B','C')

you can get a tuple containing everything except the first element using a slice:

x[1:]

Result:

('B','C')
+6
source

Source: https://habr.com/ru/post/1681172/


All Articles