Python list action method rollup _python

Source: Internet
Author: User

The examples in this article summarize the common operation methods of the list in Python for reference. The specific methods are as follows:

First, Python create a list:

Sample_list = [' A ', 1, (' A ', ' B ')]

Second, Python list operations:

Assume the following table:

Sample_list = [' A ', ' B ', 0,1,3]

1. Get one of the values in the list:

Value_start = sample_list[0]
end_value = sample_list[-1]

2. Deletes the first value of the list:

Del Sample_list[0]

3. Insert a value in the list:

SAMPLE_LIST[0:0] = [' Sample value ']

4. Get the length of the list:

List_length = Len (sample_list)

5. List traversal:

For element in Sample_list:
  print (Element)

Three, Python list advanced Operations/Tips

1. Generate a numeric increment list:

Num_inc_list = Range
#will return a list [0,1,2,..., 29]

2. Initialize the list with a fixed value:

Initial_value = 0
list_length = 5
sample_list = [Initial_value for i in Range (Ten)]
sample_list = [Initial_ Value]*list_length
# sample_list ==[0,0,0,0,0]

On this basis, readers can also continue to gather other ways of doing Python list operations to further consolidate and deepen their understanding of Python list operations.

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.