程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Tuple module of Python notes

編輯:Python

#Tuple( Yuan Zu )
#tuple Can't modify , But it can contain variable elements
#tuple use ’()' The parcel , The elements are separated by commas

#01 Use iteratible elements to create primitives
#tuple(iterable=(), /)
# Use () When creating an ancestor that contains only one element, you need to add ’,' Prevent () Is recognized as an expression

tp01 = (1,2,3,4,5)
tp = (1,)

#02 Get element index
#index(self, value, start=0, stop=9223372036854775807, /)

tp02 = (0,1,2,3,4,5,6,7)
tp = tp02.index(3)

#03 Gets the number of occurrences of the specified element
#count(self, value, /)

tp03 = (0,1,2,3,4,5,6,7)
tp = tp03.count(8)

#04 Use subscripts to get elements

tp04 = (0,1,2,3,4,5,6,7)
tp = tp04[5]

#05 Use subscript slice

tp05 = (0,1,2,3,4,5,6,7)
tp = tp05[:5]

#06 Splicing of Yuanzu

tp06 = ('a','b','c')
tp = tp05 + tp06

#07 Element judgment

tp07 = (0,1,2,3,4,5,6,7)
if 0 in tp07:
print('in')

print(tp)


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved