元组

#!/usr/bin/env python
#-*- coding: utf-8 -*-


"""
元组
"""

a = (1, 2, 3)
b =(4,)
# 索引
t = a[1] # 2
# 切片
t = a[1:] # (2, 3)
# 成员操作
t = 1 in a # True
# +
t = a + b # (1, 2, 3, 4)
# tuple(seq)
t = tuple("abcd") # ('a', 'b', 'c', 'd')
# count()
t = a.count(2) # 1
# *
t = a*2 # (1, 2, 3, 1, 2, 3)
# index()
t = a.index(2) # 1
print(t)
# del
del t #NameError: name 't' is not defined

posted @ 2018-08-15 23:08  李小样  阅读(60)  评论(0编辑  收藏  举报