To get the first element of a tuple in Python, you can use indexing. The first element has an index of 0.

For example:

my_tuple = (1, 2, 3)
first_element = my_tuple[0]
print(first_element)  # Output: 1

Alternatively, you can also use unpacking to assign the values of the tuple to individual variables:

my_tuple = (1, 2, 3)
first_element, second_element, third_element = my_tuple
print(first_element)  # Output: 1
get first element of tupple

原文地址: https://www.cveoy.top/t/topic/84r 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录