import sys #Tuples t = "1", "2", "3", 1, [123], {123545} print(t, " length", len(t)) try: t[0] = "7" except Exception as e: print(sys.exc_info()) print("\n\n", e, "\n") #Clear t = () t = "ads","dasds" print(t, " length", len(t)) x,y = t print(x,y)
Tuple vs. List
Tuple:值是不可變動,Tuple像Struct能有不同型態
List:值是可變動,每個List只能使用一種型態
參考資料:
http://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences
http://docs.python.org/3.3/tutorial/errors.html
http://stackoverflow.com/questions/1708510/python-list-vs-tuple-when-to-use-each
http://stackoverflow.com/questions/626759/whats-the-difference-between-list-and-tuples-in-python
http://www.careerride.com/python-list-vs-tuple-vs-dictionary-vs-set.aspx