tuple使用示例

tuple的简单使用

示例代码如下(tupleTest1.py):

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

t1 = ('a','b',1,2)

print t1
print t1[0]
print t1[:-1]
print t1[:2]
print t1[::-1] # reverse

运行效果如下:

$ python tupleTest1.py
('a', 'b', 1, 2)
a
('a', 'b', 1)
('a', 'b')
(2, 1, 'b', 'a')

该代码的github地址: https://github.com/mike-zhang/pyExamples/blob/master/dataStructure/tuple_examples/tupleTest1.py