Python Learning list data types and general operations

Source: Internet
Author: User

in thePythonLearning, we all know that the list is one of the most commonly used data types, and certainly one of the must-learn content., it can appear as a comma-separated value within a square bracket. What this article shares with you is Python.list data types and related operations, I want to contact the firstpythonchildren's shoes help,pythonveteran please automatically jump off this article. each element in the list is assigned a number-its location, or index, the first index is0, the second index is1, and so forth. the list of operations that can be performed includes indexing, slicing, adding, multiplying, and checking members. in addition,PythonThe method for determining the length of the sequence and determining the maximum and minimum elements has been built in. A list's data items do not need to have the same type to create a list, as long as the different data items separated by commas are enclosed in square brackets. is as follows: List1 = [' Physics ', ' H2O ', 1997, 2000]list2 = [1, 2, 3, 4, 5]list3 = ["A", "B", "C", "D"]slicing operations on a list: L[0:2] take the first to second element of a list L[2:5] take the third to fourth element of a list L[::2] interval takes list elements 1,3,5 .... the common operations of the list are as follows: Li=[' Day ', ' Eric ', ' Rain ']calculates the list length and outputs PrintLen(Li)) 3append elements to the list"Seven" Li. Append ("seven")in the list,1insert elements in a single position"Tony" Li. Insert (0, "Tony")Modify List Section2elements of the location are"Kelly" LI[1] = "Kelly"remove an element from a list"Eric" Li. Remove ("Eric")Remove the list from the2an element Li. Pop (1)Remove the list from the2to4an element forI in range (3): Li.Pop(1)reverses all elements of the list #Method1 li[::-1]#Method2 List (Reversed (LI))UseFor,Len,Rangethe index of the output list is usedenumratethe output list element and ordinal (ordinal from -start) forKvinchEnumerate (li, 100): Print (k, v)UseForall elements of the loop output list forI inRange(Len (LI)): Print (i) Source: Network

Python Learning list data types and general 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.