List (index and slice, additions and deletions), count, sort, ganso and ganso nesting

Source: Internet
Author: User

1. List

1. the list is compared to a string. data types are not restricted. and can store a lot of data.

2. representation: [] each item in square brackets is separated by commas

3. lists and strings, as well as indexes and slices

Common functions:

1. Add : Append () can only be added at the end of the list

    2. Change : Remove()

    3. Change : Index modification

    4. Check : for Loop

Common methods:

    1. Len () calculates the length of the string

    2. count () find the number of "xxx" occurrences

    3. sort () sorting

Index and slice cases for lists

Index:

Slice:

  

two. Columns table additions and deletions to change

Increase    

  

Delete   There ( pop, remove, clear, Del[delete] )

Pop the last string is deleted by default, You can also instruct the subscript to delete

  

Remove   Specifies that deleted elements Delete elements that do not exist will cause an error

Clear Clear List ( List )

   

Slice Delete   del [m:n] Remove a range from the list

del [M:N]

  

  Change

Index, Slice modification

  Check

Enquiry , column column table is ? an Iterative object , so you can go in ? for Loops

  

Three. counting, sorting

Count   count ()

  

 Sort: usually sort by numbers

sort () Ascending

sort (reverse = True) Descending

  

Reverse Sequential Rollover [:: -1]

List nesting:

The use of reduced-dimensional operation, one layer to see

  

Four . tuples and tuples nesting (tuple)

1.   tuples : commonly known as immutable lists . read-only lists, indexed and sliced, which can be used for any data type, can be queried. Loops can also be. Slices can also. But just can't change.

2. Presentation: () each item in parentheses is separated by commas

Note:

immutable is its inner child element. if the child element is a list. The elements in the list can be changed.

  

Five. Range

Range can help us get to a set of data. This data can be obtained through a For loop

  

  

  

List (index and slice, additions and deletions), count, sort, ganso and ganso nesting

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.