Python full stack development: Python tuple tuple

Source: Internet
Author: User

Meta-group

What is a tuple: "Tuples are an immutable list" (not lists, just for ease of memory)

Purpose: Used for storing multiple values, can only be read and cannot be assigned two times

Representation: parentheses () divide the elements with commas in the middle

eg

tuples = ('a','b','C','  D')
Common operations for tuples

To generate a simple tuple

tuples = tuple (range (5))print(tuples) #结果 (0, 1, 2, 3, 4)

Len (tuple)

# Computational element leader degree tuples = (0, 1, 2, 3, 4)print# results: 5

In and not in

#In and not inTuples = ('a','b','C','D')Print('a' inchTuples)#Result: TruePrint('Z' inchTuples)#Result: FalsePrint('x'  not inchTuples)#Result: TruePrint('D'  not inchTuples)#Result: False

Values for tuples

#values for tuplesTuples = ('a','b','C','D') Item=Tuples[0]Print(item)#Result: aitem = tuples[2]Print(item)#results: C#While Loopc =0 whileC <len (tuples):Print(Tuples[c]) C+=1#For Loop forIteminchtuples:Print(item)

Slices of tuples

For the slicing operations of tuples, which are not mentioned here, please refer to the slices of the string.

Python full stack development: Python string slicing

Python full stack development: Python 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.