Python learning notes (1) & mdash; list, python learning Notes list

Source: Internet
Author: User

Python learning notes (1) -- list, python learning Notes list

In python, List is a set of ordered elements included in square brackets.

Li = ["a", "B", "mpilgrim", "z", "example"]
Index

List is ordered and divided into forward (from left to right) and reverse (from right to left). The first element of any non-empty List is always List [0]. the last element of the list that contains n elements in the forward direction is List [n-1], because list starts from 0. The first element of any non-empty List in reverse order is List [-1], and the positive and negative conversion relationship is List [n] = List [len (List)-n].

Slice

In general, it is [start position: end position: Step Size]. Because the end position is not included, you need to push it back, for example, if the first two elements are used, they are [0: 2] and the values of [0] and [1] are obtained.

Add

Append, insert, and extend can be used to add elements. The main differences are:

List. append (element): append an element to the end of the List.

List. insert (location, element): insert an element at a location

List. extend (list): extend is used to connect two lists. Extend only accepts one parameter. this parameter is always list and each element in this list is added to the original List.

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.