Python List Summary

Source: Internet
Author: User
Tags python list

1 definitions

Names=[]

names=[1,2,1,1,1,]

Names=[1. ' 10 '. [[]]

2 adding elements

Names.append () Names.insert (0,10) names.extend ([0,1]) cannot names.extend (1)

3 Deleting an element

Names.remove (1) names.pop (1) names.pop del Names[0]

4 modifying elements

Names[1]= ' 111 '

names[2]= ' 222 '

5 finding elements

Names.index (1) index position names[0]

6 Ordering of elements

Names.sort Names.reserse

7 finding the number of elements

Names.count (1)

8 element length

Names.len ()

9 Comparison List

Comp (names1,names)

10 list slices

Names[1:3]

Names[::2] Names[-1]

11 iterations

For x in range (1,10)

Print (x)

12 operation in accordance with

+ * (double)

13,enumertate usage

For index,x in enumerate (names)

Print (INDEX,X)

Python List Summary

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.