Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Popping first element from a Python tuple

Tags:

python

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

For example, for

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

I would like to pop off the 'A' and have 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 the tuple?

like image 802
nao Avatar asked Jul 11 '17 07:07

nao


1 Answers

With this tuple

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

you can get a tuple containing all but the first element using a slice:

x[1:]

Result:

('B','C')
like image 83
khelwood Avatar answered Sep 28 '22 06:09

khelwood