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

What is the usage of insert in python?

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2020-01-06 10:53:1526445browse

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)

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

The output results of the above examples are as follows:

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

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!

Statement:
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