Home  >  Article  >  Backend Development  >  What does add mean in python

What does add mean in python

silencement
silencementOriginal
2019-05-21 14:47:4436238browse

What does add mean in python

The add() function in python can add the object as a whole to the dictionary. If the added element is already in the dictionary, no operation will be performed

1. add(element) function

treats the object as a whole and adds elements to the dictionary. If the added element is already in the dictionary, no operation will be performed

What does add mean in python

##Other ways to add elements

2. append(seq) function

Add the object as a whole to the end of the list. After adding Only 1 element is added to the list. The object can be of any data type, and the function has no return value.

What does add mean in python

3. The extend(seq) function

will All elements (N) are added to the end of the list one by one. After addition, the list elements are increased by N Usually, the iterable object is a list; when it is a string, each character is added to the end of the list one by one; when it is a dictionary, The dictionary keys are added to the end of the list. The function has no return value.

What does add mean in python

4. insert(index, obj) function

Invert the object As a whole, it is added to the specified position of the list. After addition, the list only adds 1 element. The method is similar to append()
Specially, when adding an element at the end of the list, the index is len(object) and the index is -1. Insert at the second to last position, not the end.

What does add mean in python

##Related learning recommendations:

python tutorial

The above is the detailed content of What does add mean 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