python3-Notes-b-003-data structure-tuple tuple ()

Source: Internet
Author: User
Tags throw exception

#Meta-group[Ordered invariant sequence](Cannot be modified)
DefTuples ():
# ---Meta-group---
#Create(A list-like way to store data,But cannot be modified)
Tuples = ("Spokesperson",21st,"Woman")
tuples =Tuple ([A,"B","C"])#Converting a list to a tuple(Note:Converting a dictionary to a tuple can lose data)
tuples =Tuple ()#Empty tuple,Don't know what to do with

#xAdd toXModifyXDelete(Attention:Don't change it.)

#Get
Tuples = ("Spokesperson",21st,"Woman")
STRs = tuples[0]#Gets the specified index data, ‘Spokesperson‘
STRs = tuples[-1]#Countdown to get Data(1Begin), ‘Woman‘
TUP4 = tuples[1:]#Intercept, <class ' tuple ';: (21, 'Woman‘)
TUP5 = tuples[0:2]# <class ' tuple ';: ('Spokesperson', 21)
tup2 = tuples + (1,2,3)#Merging tuples(Primitive tuple unchanged), <class ' tuple ';: ('Spokesperson', 21, 'Woman', 1, 2, 3)
TUP3 = tuples *3#Copy(3Report)Merging tuples, <class ' tuple ';: ('Spokesperson', 21, 'Woman‘, ‘Spokesperson', 21, 'Woman‘, ‘Spokesperson', 21, 'Woman‘)
STRs =Max (1,3,6,2.5))# max , 6
STRs = min ((1 36 2.5))

# statistics
length = len (tuples) # count = Tuples.count (21) # The number of elements

#Find
index = Tuples.index (21)#The index at which the element appears,I can't find a throw exception.
index = Tuples.index (21st,1)#From1-End
index = Tuples.index (210 2) # from 0-2

# Span style= "COLOR: #808080" > traverse
for i in tuples:
Span style= "COLOR: #8888c6" >print ( "tuple:%s"%i)

# Judge
boolean = 21 in tuples
boolean = 21 not in tuples

python3-note-b-003-data structure-tuple tuple ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.