List definition, index, add, delete, find, sort

Source: Internet
Author: User

assigning values to variables

Python is a weakly variable language that does not specify the type of the variable, and its type is determined by the value.

How to assign a variable to a value:

1, directly assigned value

A = 1

2, chain-assigned value

A = b = 1

3. sequence unpacking assignment

A, B =

Note: The number of sequence unpacking assignment variables and values must be consistent

List

A list is an ordered, modifiable sequence of elements that are separated by commas and enclosed in brackets.

List-defined methods:

1. List

2. []

3. Range

4,xrange

Note: in Xrange is canceled in Python3, but the effect of range is consistent with xrange.

Index of the list

The index of the list is similar to the index of the string, but not exactly the same, because the list can be modified, so the list can be modified by the index.

1, the index of the list

2, the modification of the list

List of methodsAdding a list

1. Append Add an element or a set of lists at the end of the list

2. Extend appends the elements of the specified sequence to the end of the list, noting that the specified sequence can only be a list

3. Insert inserts the specified element into the specified index

deletion of the list

1pop Popup Delete element on specified index, delete -1 index element by default

2. Remove removes a specified element from left to right, deleting only one

3,del Python built-in delete function, not the list of unique features

Lookup of lists

1,count counts the number of occurrences of the specified element in the string

2. Index finds the index position of the first occurrence of the specified element in the string and cannot find an error

sort the list

1,reverse the position of the index flashbacks, that is, the string is arranged backwards

2. Sort arranges the elements in the string in the order of the ASCII code table


List definition, index, add, delete, find, sort

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.