Python learning experience-basic knowledge (II.)

Source: Internet
Author: User

List common ways of doing things

1. Insert content at the end of the list--appenda=[1,2,3,4,5,6]a.append (7) Results: a=[1,2,3,4,5,6,7] Note: The list contents can be any type 2, insert content in the list pointing position--inserta=[ 1,2,3,4,5,6,7]a.insert (3,5) Results: a=[1,2,3,5,4,5,6,7] 3. Add the elements of a list to the end of the list--extenda=[1,2,3,5,4,5,6,7]a.extend ([+ +]) Results: a=[1,2,3,5,4,5,6,7,1,2,3] Note: Extend () accepts a list parameter, adds an element of the argument list to the end of the list, append () takes an object parameter, adds the object to the end of the list eg:a.append ([ Three-way]) Result: a=[1,2,3,5,4,5,6,7,1,2,3,[1,2,3] [4] There are several identical--counta=[1,2,3,5,4,5,6,7,1,2,3,[1,2,3]]a.count in the statistics list (3 Results: 2, indicating that the ' 3 ' element has 2 5 in the list, where an element in the calculation list first appears in the list--indexa=[1,2,3,5,4,5,6,7,1,2,3,[1,2,3]]a.index (5) Results: 3, which means ' 5 ' The first occurrence in the list is 3 6, directly deleting an element in the list (the first occurrence of the element)--removea=[1,2,3,5,4,5,6,7,1,2,3,[1,2,3]]a.remove (5) Results: a=[ 1,2,3,4,5,6,7,1,2,3,[1,2,3]] 7, delete the element of a ' position ' in the list, and print out the deleted element--popa=[1,2,3,4,5,6,7,1,2,3,[1,2,3]]a.pop (3) Results: 4, Represents the Delete element on the list position ' 3 ', the deleted element is ' 4 ' a=[1,2,3,5,6,7,1,2,3,[1,2,3]

Python learning experience-basic knowledge (II.)

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.