Python List of list-

Source: Internet
Author: User
Tags python list

Python list

The list is the most frequently used data type in Python.

A list can accomplish the data structure implementation of most collection classes. It supports characters, numbers, and strings that can even contain lists (that is, nesting).

The list is identified by [], which is the most common type of composite data for Python.

The cut of the value in the list can also be used to the variable [head subscript: Tail subscript], you can intercept the corresponding list, from left to right index default 0, starting from right to left index default-1, subscript can be empty to take the head or tail.

Inline Functions

Example Analysis:

1. Add a new object at the end of the list

li=[One,one,one,'aa','bb','  cc'] li.append ('dd') print (LI)

2. Insert an element before the specified index position

li=[One,one,one,'aa','bb','  cc']li.insert (3,'+ ') Print (LI)

3. Deleting an element

li=[One,one,one,'aa','bb','  cc'] del li[5]print (LI)

4. Popup Elements

li=[ One, A, -,'AA','BB','cc'] Li.pop () #默认是栈顶元素print (LI) Li=[ One, A, -,'AA','BB','cc'] Li.pop (0) #指定元素值print (LI)

5. Delete the value element (without knowing the location, but knowing the value)

li=[One,one,one,'aa','bb','  cc']li.remove ('cc') print (LI)

6. Permanent sorting by letter

li=[, and]li.  Sort ()  #永久排序print (li) Li=[,]sorted (LI)  # Temporary sort print (LI)

7. List reversal

li=[,]li.reverse () #反向列表永久print (LI) Li=[one by One, ]list,reversed (li) #反向列表暂时print (Li )

8. Return the list length

li=[,]len (li) 

9. Clear the list

li=[, and]li.  Clear () print (LI)

10. Copy the list

li=[,]ri=li.copy () print (RI) 

11. Returns the number of specified elements in the list

li=[One,one, one,one]li.count (one)

12. Append sequence B at the end of the list

li=[,]b=['aa', ' BB ' ]li.extend (B) print (RI)

13. Returns the first position of a specified element in a list

li=[One,one, one,one]li.index (one)

14. Specify whether the element returns a bool value in the list

li=[One,one,one,one, one in litrue

Python List of list-

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.