Python元组Tuple

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hju22/article/details/85057819

一、元组定义

1、定义元组-用小括号()

student=("小明","小王","小李","小红")

2、定义空元组

 name=()

3、定义只含一个元素的元组

元素后面必须有逗号,

course=("Java",)

二、访问元组元素

在这里插入图片描述

三、元组操作

1、元组中的元素不允许修改

2、元组中的元素不允许删除

3、可以删除整个元组-del语句

student=("小明","小王","小李","小红")
del student

四、元组长度-len()

student=("小明","小王","小李","小红")
print(len(student))

在这里插入图片描述

五、元组中元素的最大值-max()

score=(5,3,2,6,1)
print(max(score))

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/hju22/article/details/85057819