Use of lists in Python

Source: Internet
Author: User

Purpose: Proficiency in the use of list functions, convenient management of multiple variable values


Environment: Ubuntu 16.04 python 3.5.2


Scenario: The list should be used in data processing often to use a type, can be ordered, combined with the operation of the value of storage, is a useful function ... This is the last piece of notes to be collated, to find that typography is a waste of time, that there is no communication, or that it is quicker to write notes in a similar way to OneNote.


List:

List (), which is an iterative object, commonly used for, join, sort, reverse, sorted, index, and slice.

Some of its own operations include:

box = list () or box = [] Set empty lists

Box.append (' value ') trailing append element

Box.insert (1, ' value ') Index insert Element

Box[0] = ' value ' index replace or write element

Box.pop () Delete trailing elements

Box.pop (1) Index Delete element

Box.index (' value ') gets the element subscript

Del Box[1] Delete the specified element

Sorted (box) returns a new forward list


Mate Method:

Sort () in-place forward sort

Reverse () reverse sort in place

Delimiter. Join (box) to specify a symbolic connection list element as a string

Slice reference string (private chain)


Extended:

The list can be generated in a list with a quick and concise style.

New_list = [x for x in range] if not x% 2]



This article is from the "Rickyhul" blog, make sure to keep this source http://rickyh.blog.51cto.com/10934856/1955648

Use of lists in Python

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.