The road to wudao-one day during the refining period (from the high ground in wanshu) and from the high ground in a heavy City

Source: Internet
Author: User

The road to wudao-one day during the refining period (from the high ground in wanshu) and from the high ground in a heavy City

List some simple basic methods:

Example: A list

Usernames = ['Li si', 'wang 2', 'zhang san', 'machin']

Index: usernames [0] # Starts from 0 and ends from-1 (left to right)

Slice: usernames [] = ['wang 2'], that is, list [header: tail: Step Size], Gu header regardless of the end (left closed and right open), usernames [2:], from the third element to the last one

Partition assignment: usernames [1:] = ['ss'], that is, replacing the element whose subscript starts from 1,

# Len (usernames)-> List length, max (usernames), min (usernames), extreme values in the list

Add:

# Usernames. append ('marath') # append an element to the list: ['lily', 'wang 2', 'zhang san', 'machin', 'marath']

# Usernames. insert (index, content to be inserted), before the index !!

Delete:

# Del usernames [2], delete element # del is to delete variable

# Usernames. pop (INDEX). If no index is added, the last element is deleted by default.

# Usernames. remove (INDEX), in fact, slice can also be deleted

Change:

# Directly modify usernames [1] = 'mmmm', And the slice can also be modified.

Query:

# Usernames. index ('elemental) locate the position of an element in the list (index)

Others:

Usernames. count (element, start, end) calculates the number of times an element appears in the list (between start and end)

# Usernames. extend (['2', 33]), similar to list Splicing

Usenames. reserve () reverse list

Usernames. sort () sorting

Usernames. copy () or import copy. copy (usernames) shallow copy # reference

Import copy. deepcopy (usernames) Deep replication with caution (re-opening a memory)

 

Tuples: The elements are unchangeable ('ss', 'ddd ')

There are two ways to remember: index count

 

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.