Home > Backend Development > Python Tutorial > What is the usage of insert in python?

What is the usage of insert in python?

爱喝马黛茶的安东尼
Release: 2020-01-06 10:53:15
Original
26509 people have browsed it

What is the usage of insert in python?

Description

The insert() function is used to insert the specified object into the specified position in the list.

Syntax

insert() method syntax:

list.insert(index, obj)
Copy after login

Parameters

index -- object obj The index position to be inserted.

obj -- The object to be inserted into the list.

Return value

This method has no return value, but will insert the object at the specified position in the list.

Examples

The following examples show how to use the insert() function:

#!/usr/bin/python
aList = [123, 'xyz', 'zara', 'abc']
aList.insert( 3, 2009) 
print "Final List : ", aList
Copy after login

The output results of the above examples are as follows:

Final List : [123, 'xyz', 'zara', 2009, 'abc']
Copy after login

numerouspython training videos, all on the python learning network, welcome to learn online!

The above is the detailed content of What is the usage of insert in python?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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