Python-day3 list Inside Hi method

Source: Internet
Author: User

1. Correct creation of List objects

Li = List ([1,2,3,4])
Li2 = List ((1,2,3,4))

2.append

result = Li.append (5)

3.clear

result = Li.clear ()

4. Copy---1. Shallow copy, deep copy

Eg: the list assumes that there is a dictionary or a list, a shallow copy refers to a copy only the first layer, the deep copy as the name implies the copy to the bottom.

5.extend--Extensions (list, ganso)

Li = List ([1,2,3,4])
result = Li.extend ([55, 55,])
Print (LI)

6.insert Increase in index location

Li = List ([1,2,3,4])
result = Li.insert (2,33)
Print (LI)

7.pop Remove, return the removed value, remove the last one by default

Li = List ([1,2,3,4])
Resulet = Li.pop (0)
Print (LI)
Print (Resulet)

8.remove Remove---Remove from left to right and return none after removal

Li = List ([1,2,3,4])
Print (LI)
result = Li.remove (1)
Print (LI)

9 reverse reversal, all sequences are reversed

Li = List ([1,2,3,4])
Print (LI)
result = Li.reverse ()
Print (LI)

Learn the following points and practice them in a scene

Python-day3 list Inside Hi method

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.