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

 

#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)