python-元組

來源:互聯網
上載者:User

標籤:list   def   對象   for迴圈   python   迴圈   不可   pre   修改   

#元組 元素不可以被修改,不增加或刪除
#
# li = [11,22,12,33,134]
# tu = (11,22,33,44,556,32,67,)
#一般寫元組的時候最後加一個逗號
#tuple

#索引
# v = tu[0:4]
# print(v)

#可以被for迴圈 可迭代對象
# for i in tu:
# print(i)

#字串轉換 元組
# s = "dlkagje1232"
# tu1 = tuple(s)
#
# tu2 = tuple(li)
#
# print(tu1,tu2)

#元組轉列表 字串
#
# tu = (11,22,"33","alds","dfpk")
#
# li = list(tu)
# print(li)
#
# s=""
# for i in tu:
# s = s + str(i) #注意要把數字,轉換字串
# print(s)
#
# tu1 = ("212","sdf")
# s1 = "_".join(tu1)
# print(s1)# 元組中沒有數字,可以直接jion 直接拼接


#元組的一級元素不可修改/刪除/增加

tu = (111,"234r2",("dag",12),[("ddd","daf")],True,44,99)
#取出 ddd
v= tu[3][0][0]
print(v)
v = tu[3]
print(v)
tu[3][0]=45676
print(tu)


#def count(self, value): # 統計元組內值所出現的次數

#def index(self, value, start=None, stop=None): # 根據索引找到相應的值

python-元組

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.