python--Meta-Group

Source: Internet
Author: User

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

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.