#!/usr/bin/env python
# -*- coding:utf-8 -*-
# __author__:anxu.qi
# Date:2018/11/21
# 元組的特性,元組的元素不可被修改,元素的內部可以修改
################################## 元組 ###############################
# 元組和列表幾乎是一樣的,也是一組數,只不過他一旦建立,便不能再修改,所以又叫只讀列表。
# 列表是可以進行修改的,元組是不能修改的
name_list = ("beijing","shanghai","jinan","shandong")
## 索引
print(name_list[0])
# beijing
## len
print(len(name_list))
# 4
## 切片
print(name_list[0:2])
# (`beijing`, `shanghai`)
## for 迴圈
for i in name_list:
print(i)
"""
beijing
shanghai
jinan
shandong
"""
################################## 刪除元組元素報錯 ###############################
name_list = ("beijing","shanghai","jinan","shandong")
# del name_list[0]
# TypeError: `tuple` object doesn`t support item deletion (說的是“tuple”物件不支援刪除項)
################################## count 統計個數 ###############################
# def count(self, value):
# 統計元素個數
name_list = ("beijing","shanghai","jinan","shandong","beijing")
print(name_list.count("beijing"))
# 2
################################## index 獲取索引 ###############################
# def index(self, value, start=None, stop=None):
# 獲取指定元素的下標位置
name_list = ("beijing","shandong","shanghai","jinan","shandong")
print(name_list.index(`shandong`)) # 獲取的下標只能從左往右
# 1
################################## 元組 ###############################