首页 > 编程语言 > 详细

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

时间:2015-07-02 23:52:43      阅读:288      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!