tuple tuples
Why do I need tuples ?
For example : Print the user's name
Userinfo1 = "Fentiao 4 Male"
Userinfo[0:7]
Conclusion : The method of extracting name / age / Gender in the string is inconvenient , the birth tuple .
First, definition of tuples
( you can think of tuples as a container, and any data type can be placed inside this container. )
- Create tuples by assigning values;
- Create tuples from factory method
?- define an empty tuple
tuple = ()
?- A tuple that defines a single value , Be sure to add a comma after this element
Tuple = (A,)
?- General tuples
tuple = (b, 8, ' male ')
Second, Tuple Properties
? You cannot change the value of a tuple arbitrarily ;
? assign a value to a tuple individually , extended to multiple variables can also be divided by the tuple way
Do not assign a value
Third, operation of tuples
tuples also belong to the sequence, which can be performed as follows :
index, slice, repeat, connect, and view length
Delete
Four, Tuple's method
? T.count (value)-->int
returns the number of occurrences of value in a tuple ;
? T.index (value)
returns the offset of value in the tuple ( that is, the index value )
Five, the cycle of the tuple
The loop of the string:
Can iterate over objects
Demo: Port selector prototype
Enumeration method
Zip
python--Meta-Group