List operations in Python (add, delete, change, search, reverse, sort)

Source: Internet
Author: User

The index of the list (subscript) starts at 0 and the last one can be represented by-1.

1. Add ( append (), insert ())

2. Delete (pop (), remove (), Del, Clear ())

Stus.pop () #默认删除最后一个

Stus.pop (1) #删除指定位置

Stus.remove (' Nancy ') #删除list中某个元素, with repeated words, delete the first one

Del Stus[-1] #删除指定下标的元素

Stus.clear () #清空整个list

3. Modification (directly by subscript)

STUS[2] = ' Mike ' # Specify location modification

4. View (count (), index ())

To view values at a specified location by using the subscript

5. Invert (reverse ()), sort (sort () )

Reverse () reversal

Sort () default ascending, want descending sort plus reverse=true

6. Multidimensional arrays

List operations in Python (add, delete, change, search, reverse, sort)

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.