List in Python

Source: Internet
Author: User

The list in Python is a set of ordered collections that can be added and removed at any time.

To get the length of the list, you can use the Len () method.

To access an element in the list can be accessed by subscript, and the subscript starts at 0.

Of course, if the last element of the access can be accessed using the subscript 1, the second-lowest one can be accessed using-2.

Adding elements to the end of the list element can be increased using the Append () method.

Use Insert (Index,value) to insert an element into the specified position.

Deleting elements at the end of the list can use the Pop () method

Deleting the first few elements of the list can be deleted using the pop (i) method.

Of course the list can store different types of elements.

Here's a look at the specific example:

stulist=[' Zhangsan ', ' Lisi ', ' Wangwu ']print len (stulist) print stulist[1];p rint stulist[-1]stulist.append (' Sunliu ') Print Stulist[-1]stulist.insert (1, ' Mary ') print Stulist[1]stulist.pop () print stulist[-1]stulist.pop (1) Print stulist [1]numlist = [B, ' C ', ' String ']print numlistprint numlist[0]
Running results such as:


List in Python

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.