Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Lấy phần tử đầu tiên từ tuple Python (pop first)

Tuple immutable → không thể remove element. Workaround: convert tuple → list → remove → convert back.

Ví dụ

>>> T1 = (1, 2, 3, 4)
>>> L1 = list(T1)
>>> L1.pop(0)
1
>>> L1
[2, 3, 4]
>>> T1 = tuple(L1)
>>> T1
(2, 3, 4)