python Python中的元组

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Python中的元组相关的知识,希望对你有一定的参考价值。

#   The main difference between a tuple and a list is that the contents of a tuple cannot be changed afterwards

# declaring a tuple
pi_tuple = (3,1,4,1,5,9)
print('The new tuple is: ', pi_tuple)
#converting a tuple into a list:
new_tuple = list(pi_tuple)

#converting a list into a tuple:
new_list = tuple(new_tuple)

#obtaining the length of a tuple
len(new_tuple)
print('The length of the tuple is', len(new_tuple))

#obtaining the minimum value in a tuple
min(new_tuple)
print('The minimum value in the tuple is', min(new_tuple))

#obtaining the maximum value in a tuple
max(new_tuple)
print('The maximum value in the tuple is', max(new_tuple))

以上是关于python Python中的元组的主要内容,如果未能解决你的问题,请参考以下文章

python中的元组

python学习之第五篇:Python中的元组及其所具有的方法

Python中的元组声明

python Python中的元组

python中的元组

python中的元组和列表有啥区别,哪个更有效[重复]