Python Learning meta-group

Source: Internet
Author: User

Tuples-a list with shackles

1. The use of tuples is similar to the list, but the list permissions are large, the list can be arbitrarily deleted or modified elements, but tuples can not be changed

2. Create and change tuple basic operations:

Created: tuple1= (' 1 ', ' 2 ', 3 ...) Note that the key to creating a tuple is "," comma, tuple1= (1) This is not a tuple, tuple1= (1,) or tuple1=1, is a tuple; Create an empty tuple tuple1= (); Tuple1 =1,2, 3 This is also a meta-group

Access tuples: tuple1[1], tuple1[2:], tuple1[:], Tuple1[:3]

Different from list: cannot be changed, cannot be assigned

3. Update and delete tuples:

1) Slice the tuple, add a new element, and then splice the slices

such as: t= (' 11 ', ' 22 ', ' 333 ', ' ha ha '), insert ' whining ' after the second element

t = T[:2] + (' whining ',) + t[2:]

2) Delete the tuple:

Delete element in tuple:tuple1 = tuple1[:1]+tuple1[2:] Delete second element

Delete entire tuple: del t

4. Which operators can be used on tuples:

1) Stitching tuple1 = tuple1[:1]+ (' whining ',)

2) Repeat operator: 8* (8,) 8 Repeat 8 times

3) relational operator:> < =

4) member operators: in and not in

5) logical operator: and OR

Python Learning meta-group

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.