Home > Backend Development > Python Tutorial > Summary of how to use list in python (picture and text)

Summary of how to use list in python (picture and text)

不言
Release: 2018-09-20 16:55:46
Original
3263 people have browsed it

This article brings you a summary (pictures and texts) of how to use list in Python. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

1. A list is an ordered collection in which elements can be added, modified, or deleted at any time.

Example: Listclassname = ['Jack', 'Tom', 'Mark']

## List can obtain elements according to the index, such as: ListclassName

##The list index starts from 0, and the last element index is len(listClassName)-1;

If you want to get the last element, in addition to calculating the index position, you can also use

-1

Do index and get the last element directly:

1.1 Get the number (length) of the list: Use the len() function to get the list The number of elements (elements are calculated starting from 1):

len(listClassName)

1.2 Add elements: Use the append() function, you can Add elements to the end of the list:

listClassName.append('Xiao Ming')

1.3 Insert elements: Use the insert() function to insert elements into the specified Position:

1.4 Replace element: Replace an element with another element and assign it directly to the corresponding index position:

1.5 The data types of the elements in the list can also be different:

1.6 The list elements can also be another list:

The above is the detailed content of Summary of how to use list in python (picture and text). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template