Python基礎_元組
# @Time:2020/12/15 21:09
# @Author:李 祥
# @File:Tuple.py
# @Software:PyCharm
# Tuple(元組) 內容不可變,但是包含可變物件
# 相像列表list
#
tup1 = () # 建立空元組
print(tup1, type(tup1))
tup1 = (50)
tup2 = (50,) # 元組的必備條件為 , 單元素最後,不可省。 多元素可省略
print(tup1, type(tup1))
print(tup2, type(tup2))
tup1 = 50, 60, 70
tup2 = 50,
print(tup1, type(tup1))
print(tup2, type(tup2)) # 建立元組可以不加() 不推薦
# 連線(增)
tup1 = (1, 2, 3)
tup2 = (4, 5, 6)
tup = tup1 + tup2
print(tup, type(tup))
# 刪(刪除元組物件,不可刪內部元素)
tup1 = (1, 2, 3)
print(tup1)
del tup1
print(tup1) # 報錯,因為已經刪除
# 改 (只能更改內部可變變數)
list1 = [2, 3]
tup1 = (1, list1)
print(tup1)
list1.append(4)
print(tup1)
# 查
tup1 = (1, 2, 3)
print(tup1[0]) # 根據下標訪問
print(tup1[::-1]) # 切片
# 迴圈
tup1 = (1, 2, 3)
for i in tup1:
print(i)
# in not in
tup1 = (1, 2, 3)
if 3 in tup1:
print("true")
else:
print("false")
# 計數 count 最大最小max min 求和 sum 長度 len
# 類比list
# 強制型別轉換 tuple()
# 字串
s = "student"
tup = tuple(s)
print(tup, type(tup))
# 列表
list1 = [1, 2, 3]
tup = tuple(list1)
print(tup, type(tup))
# 生成器物件 (後期詳細補充)
s = (i*2 for i in range(5))
print(tuple(s))
相關文章
- Python 基礎 3 - 元組Python
- Python基礎(05):元組Python
- python list列表基礎(元組)Python
- python基礎之元組,列表Python
- Python基礎-元組小結Python
- python基礎:元組轉字典Python
- python之tuple元組,基礎篇Python
- python基礎之列表list元組tuplePython
- Python - 基礎資料型別 tuple 元組Python資料型別
- Python基礎知識七 元組&字典&集合Python
- 豬行天下之Python基礎——3.2 列表 & 元組Python
- 列表、元組、字串是有序序列嗎?Python基礎教程字串Python
- Python基礎:資料型別-列表與元組(6)Python資料型別
- python基礎之序列型別的方法——列表&元組Python型別
- Python零基礎學習筆記(二十)——tuple元組Python筆記
- Python基礎語法2 元組 & 字典 & 選擇結構Python
- 【菜鳥教程筆記】python基礎之元組的使用筆記Python
- Python 元組Python
- Python 入門學習 -----變數及基礎型別(元組,列表,字典,集合)Python變數型別
- Python tuple(元組)Python
- python的元組Python
- Python元組tuplePython
- python-元組Python
- Python元組詳解Python
- python元組和列表Python
- 認識Python 元組Python
- 06_Python 元組Python
- python--元組tuplePython
- Python 建立元組tuplePython
- Python速通(元組)Python
- 位元組碼基礎
- Python列表、元組、字典使用Python
- Python的元組()與字典{}Python
- Python 學習之元組Python
- python元組的特點Python
- python命名元組如何理解Python
- Python的元組()與字典 { }Python
- 初學Python(五)——元組Python