Python Learning Summary 3: Summary of Operations for tuples and lists

Source: Internet
Author: User

Reference Blog: http://www.cnblogs.com/QG-whz/p/4782809.html

1. Whether variable

Tuples: defined with () or tuple functions, immutable (values of elements and entire tuples);

List: defined with [] or list function, variable.

2. Summary of Operation Methods

List: Python sequence operations are all common, such as indexing, sharding, joins, multiplication, and so on. And because the list is modifiable, there are several ways to assign elements, delete elements, and assign values to shards.

Summary of List (object) methods:

            APPEND: to append a new element to the end of the list
            count: Used to count a Occurrences of elements in a list
            Extend: Append multiple values from another sequence at the end of the list
        & nbsp   Index: Used to find a value from a list the index position of the first match
            insert: Used to insert an object in the corresponding position in a list
            Pop: This method pops an element from the list, which is the last one by default. and returns the popup element
            Remove: Removes the first occurrence of a value from the list. Unlike pop, the method does not return an element that is removed.
            Reverse: This method stores the sequence direction; Note that the method changes the list but does not return a value.
                          If you need to reverse iterate over a sequence, you can use the reversed Function. Instead of returning a list, this function returns an iterator object that you can use to convert the iterator object to a list:
            sort: Used for sorting in the original location list. The original location means that the list will be modified.
                     sorted reversed

Tuples: There are fewer operations than lists, such as attend, insert, and more. Other operations, such as shards, index operations, and so on, are similar to lists. Therefore, in the use of tuples, always remember that tuples are not modifiable, and naturally know what the tuple has to do.

Python Learning Summary 3: Summary of Operations for tuples and lists

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.