a = (1, 2, 3, 4)
b = ('abc', 'dong', 'you', 'yuan')
print a[0]
print b[1:3] # 下标1到3(不包括3)
print b[:] # 所有下标
# 输出结果:
# 1
# ('dong', 'you')
# ('abc', 'dong', 'you', 'yuan')
tup1 = ('abc', 'dong', 'you', 'yuan')
tup2 = ('12', '34')
# tup1[0] = 'cde' # 非法操作
tup3 = tup1 + tup2
print tup3
# 输出结果
# ('abc', 'dong', 'you', 'yuan', '12', '34')
tup1 = ('abc', 'dong', 'you', 'yuan')
print tup1
del tup1
print tup1
# 输出结果 出现报错信息
# ('abc', 'dong', 'you', 'yuan')
# print tup1
# NameError: name 'tup1' is not defined
tup1, tup2 = (123, 'dong'), (456, 'yuan')
print cmp(tup1, tup2)
print cmp(tup2, tup1)
tup3 = tup2 + (789,)
print cmp(tup2, tup3)
# 输出结果
# -1
# 1
# -1
tup1 = (1, 2, ['a', 'b'])
print tup1
tup1[2][0] = 'A'
tup1[2][1] = 'B'
print tup1
# 输出结果
# (1, 2, ['a', 'b'])
# (1, 2, ['A', 'B'])