Hi method in Python-day3 list, python-day3hi

Source: Internet
Author: User

Hi method in Python-day3 list, python-day3hi

1. Create a list object correctly

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

2. append

Result = li. append (5)

3. clear

Result = li. clear ()

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

For example, if the list contains a dictionary or list, you can copy only the first layer, and then copy the dictionary or list to the bottom layer as the name suggests.

5. extend -- extended (list, ancestor)

Li = list ([1, 2, 4])
Result = li. extend ([55,55,])
Print (li)

6. insert is added at the specified index location.

Li = list ([1, 2, 4])
Result = li. insert (2, 33)
Print (li)

7. pop removal. The removed value is returned. The last bit is removed by default.

Li = list ([1, 2, 4])
Resulet = li. pop (0)
Print (li)
Print (resulet)

8. remove --- remove from left to right. After the removal, the return value is None.

Li = list ([1, 2, 4])
Print (li)
Result = li. remove (1)
Print (li)

9 reverse: All sequences are reversed.

Li = list ([1, 2, 4])
Print (li)
Result = li. reverse ()
Print (li)

The following learning points are used to practice in scenarios:

 

Related Article

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.