Python list operation

Source: Internet
Author: User
Tags python list

Lists List

Features: ordered, support for different types of elements in a list, mutable (using the Sort method to sort, affects the list itself rather than creating a new list-this is different from the string, so the string is immutable)

The list is also an object in Python, so he also has properties and methods help (list)

List operation:

1, orderly characteristics, you can use for. In.. Looping through lists

2, Basic: Increase, delete del, change, check

3. Intercept list: [2][-2] The penultimate [1:] Start intercept from the second element [2:4] (slice)

4. Script operator: + connection, * repeat

First, the function

1, CMP (LIST1,LIST2) #比较2个列表中的元素? Http://www.runoob.com/python/att-list-cmp.html

2, Len ()

3, Max () method returns the maximum value in a list element

4, Min () method returns the minimum value in a list element

5. The list () method is used to convert tuples to lists

Second, the method

1, append (), no return value, add new object at the tail, modify the original list directly

2. The count () method is used to count the number of occurrences of an element in a list

3, Extend (), no return value, add a new sequence at the tail, directly modify the original list

4. Index () find the index position of the first occurrence of a value from the list

5, insert (index, obj) No return value, directly inserted

6, Pop (index) removes an element from the list (the last element by default), and returns the value of the element

7. Remove () Removes the first occurrence of a value in the list

8. Reverse () flips the elements in the list

9, Sort (func ()) Order, can add function to specify Sort method

Python list operation

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.