Python Small white Road (list of feature syntax three)

Source: Internet
Author: User

List
One, the format of the list: the variable is studentlist = [' Zhangsan ', ' Male ', 29], the element can be of different data types.
Second, print the list: Print the student name print (studentlist[0])
Third, the circular traversal of the list
1. For student in Studentlist:
Print (studentlist)
2, i = 0
length = Len (students)
While I < length:
Print (Studentslist[i])
i + = 1
Iv. increase, deletion, modification and sequencing of the list
1. Add elements: Append, Extend, insert
Append: You can append an element to the end of the list by append.
Extend: By extend you can add elements from another collection to the table one by one.
Insert:insert (Index.object) inserts the element object before the index at the specified position.
2. Modifying elements
When you modify an element, you use the subscript to determine which element is being modified before you can modify it.
3. Find elements: In, not in, index, count
Looking for is to see if the specified element exists.
In: The presence returns TRUE, otherwise false is returned.
Not in: as opposed to in.
Index:a.index (' A ', 1,4) looks for an index and does not exist to report an exception.
Number of Count:a.count (' A ') statistics.
4. Delete elements: Del, pop, remove
Del: Delete del studentlist[0] according to the subscript.
Pop: Deletes the last element Studentlist.pop ().
Remove: Delete studentlist.remove (' name ') based on the value of the element
5. Sorting: Sort, reverse
Sort: The list is rearranged in a specific order, by default, from small to large, and parameter reversetrue can be changed to reverse, from large to small.
Studentlist.reverse () Studentslist.sort (reverse=true)
V. Nesting of lists
An element in a list is another list.

Python Small white Road (list of feature syntax three)

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.