Pytion 002 List 元组 不可变对象

# -*- coding: cp936 -*-
#D:\workspace\Pytion_workspace\001_list.py


#=================list====================
print '--001 def list'
mList = [1,2,3,4]
print(mList)        # iterator element of list
print mList[0]      # print element of list
print mList[1]


#==================元组==================
print '--002元组<泛型>, 容器内,只能有一种'
a =(2,4,7)
print a
print a[0]

#==================(元组)是不可变对象,不可以对它进行重新赋值===================

a[0]=4    
#
#Traceback (most recent call last):
#  File "D:/workspace/Pytion_workspace/001_list.py", line 17, in <module>
#    a[0]=4
# TypeError: 'tuple' object does not support item assignment

posted on 2016-07-02 18:07  fantiejun0436  阅读(85)  评论(0)    收藏  举报

导航