002 list and metadata, 002 list tuples

Source: Internet
Author: User

002 list and metadata, 002 list tuples

It should be similar to array, but there are many built-in methods.
# Definition
A = ["wuchao", "jinxing", "123", "456", "789", "110"]

Basic operations
# Slice
Print (a [1: 4])
Print (a [2:]) # If the last one is null, the last one is obtained. If it is-1, the last one is obtained, and so on.
Print (a []) # Add a step. If the step size is negative, the system starts to retrieve the index number of the first parameter and the index number of the second parameter.
# Here is the index number starting from 4th, with the number of steps being 2, to the left (tail), that is, the position of "jinxing"

# Add appendinsert
A. append ("qing") # append to the last position
A. insert (-1, "hua") # add to any location
Extend, also add Method

# Batch Modification
A [3: 5] = ["xiongdi", "qizi"]

# Delete removepopdel
A. remove ("wuchao") # Delete by value
B = a. pop (2) # deleting an index will return a value. If no index is specified, the last one will be deleted.
Dela [] # Powerful Deletion

Built-in Method
# Count method
Num = a. count ("qing") # There are 2 qing

# Extend Method
X = [1, 2, 3]
Y = [4, 5, 6]
X. extend (y) # x adds elements in y

# Index Method
Print (a. index ("qing", a. index ("qing") + 1 ))

# Reverse method, invert
A. reverse ()

# Sort method sorting method
X. sort (reverse = True)

# Not in
Print ("hua" in)

# Clear the content
X. clear ()

# Checking whether the list is correct
Type (x) islist

Related Article

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.