Python full-stack development: python tuple, python Development Group tuple

Source: Internet
Author: User

Python full-stack development: python tuple, python Development Group tuple
Tuples

What is a tuples: "tuples are an unchangeable List" (not a list, just to facilitate memory)

Purpose: it is used to store multiple values. It can only be read but cannot be assigned twice.

Format: Use commas to separate each element in parentheses ().

Eg:

tuples = ('a','b','c','d')
Common Operations of tuples

Generate a simple tuples

Tuples = tuple (range (5) print (tuples) # result (0, 1, 2, 3, 4)

 

Len (tuple)

# Calculate the length of tuples = (0, 1, 2, 3, 4) print (len (tuples) # result: 5

 

In and not in

# In and not intuples = ('A', 'B', 'C', 'D') print ('A' in tuples) # result: trueprint ('Z' in tuples) # result: Falseprint ('x' not in tuples) # result: Trueprint ('D' not in tuples) # result: False

 

Values of tuples

# Tuples = ('A', 'B', 'C', 'D') item = tuples [0] print (item) # result: aitem = tuples [2] print (item) # result: c # while loop c = 0 while c <len (tuples): print (tuples [c]) c + = 1 # for Loop for item in tuples: print (item)

 

 

Shard of tuples

The slicing operation of tuples is not described here. Please refer to the slicing of strings.

Full-stack Python development: python string Slicing

 

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.