My Python self-learning Path 2: List learning, python self-learning path list

Source: Internet
Author: User

My Python self-learning Path 2: List learning, python self-learning path list

I learned the path of Python by myself, and we started to learn the list in a rough way.

List is the most basic data structure in Python and the most common data type.

1. Create a list:

2. Common List operations: indexing, slicing, adding, and deleting.

(1) index: the value in the index access list can be used.

 

(2) Slice: truncates values in the list.

Tip: The Slice index of the list starts from 0. I understand it:

List [] outputs 2 and 3.

(3) Add: add data to the list.

List. append (obj) is added to the end of the list.

List. extend (seq) append multiple values in another sequence at a time at the end of the list (extend the original list with the new list)

 

(4) Delete: list. pop (obj) removes a data entry at the end of the list. obj is the index position of the list. List. remove (obj) removes the first matched value. obj is a value.

Pop ():

Remove ():

 

3. List common methods.

List. extend ()

 

List. index (obj), obj is the element in the list, list. index (obj) gets the index position of obj.

List. insert (index, obj), insert an element at the index position

List. reverse () elements in the reverse list

 

List. sort () sorts the original list

List. len () Get the list Length

Cmp (list1, list2) compares two list elements

List + list1 is equivalent to list. extend (list1)

List * 2

Max (list): returns the maximum value of the list element.
Min (list): returns the minimum value of the list element.
List (seq): convert a tuple to a list.

The methods I know mainly focus on these aspects. If you have any shortcomings, I hope you can understand them.

 

 

 

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.