This article mainly introduces the detailed explanation of the pop function and append function in python. It has certain reference value. Now I share it with you. Friends in need can refer to it
pop() function
1. Description
pop() function is used to remove an element from the list (default is the last element ), and returns the value of the element.
Syntax
##pop() method syntax:
list.pop(obj=list[-1])
2. Parameter
obj – Optional parameter, the object to remove the list element.3. Return value
This method returns the element object removed from the list.4. Example
The following example shows how to use the pop() function:#!/usr/bin/python aList = [123, 'xyz', 'zara', 'abc']; print "A List : ", aList.pop(); print "B List : ", aList.pop(2);
The output result of the above example is as follows:
A List : abc B List : zara
##append() function
1. DescriptionThe Python list append() method is used to append (add) the incoming object to an existing list.
2. SyntaxThe following is the syntax of the append() method-
list.append(obj) Python
obj - This is the object to be added to the list.
4. Return valueThis method does not return any value, but updates the existing list.
5. ExampleThe following example shows the usage of the append() method.
#!/usr/bin/python3 list1 = ['C++', 'Java', 'Python'] list1.append('C#') print ("updated list : ", list1) Python
When running the above program, it produces the following result-
updated list : ['C++', 'Java', 'Python', 'C#']
Gif Demonstrate the execution process of Python while statement
Related recommendations:
A brief discussion on the change of value after dictionary append to list in pythonThe above is the detailed content of Detailed explanation of pop function and append function in python. For more information, please follow other related articles on the PHP Chinese website!