码迷,mamicode.com
首页 > 编程语言 > 详细

Python 2.7.9 Demo - 015.元组的定义、取值、遍历

时间:2015-07-02 23:55:03      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

 

#coding=utf-8
#!/usr/bin/python

final_list = (a, 1, b, 2, c, 3);

print final_list[0];
print final_list[1:3];
print final_list * 2;
print final_list + final_list + final_list;

# 原组不能被重新赋值
# TypeError: ‘tuple‘ object does not support item assignment
# final_list[0] = ‘z‘;

# 遍历
print(for each method 1 : );
for data in final_list:
    print data;

print(for each method 2 : );
for i in range(0, len(final_list)) :
        print final_list[i];

 

Python 2.7.9 Demo - 015.元组的定义、取值、遍历

标签:

原文地址:http://www.cnblogs.com/nick-huang/p/4617287.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!