• Register
100 points
4

Today we will see in our website kodlogs how we use the pop function in Python. Pop, remove and clear their work is almost the same. As you know the name of the function of Python.  The same thing happens today. Python language is becoming No. 1 in programming and the salary of programmers is also very high. By learning Python in a very short time, you can create a lot.

Python programming is a general-purpose, used in almost all fields, including: 

  • Data science
  • Web development
  • Finance and trading
  • Computer graphics
  • Basic game development
  • Security and penetration testing

Now let's talk about what the pop function does. The pop element returns the pop element based on the index. The remove element removes the element at the base. Let's look at some examples and try to understand the pop function.

>>>list1=[2,4,6,8,10,12]
>>>print(list1.pop(),list1)

O/P
[2,4,6,8,10]

>>>list=[2,4,6,8,10,12]
>>>print(list1.pop(0),list1)

O/P
[4,6,8,10,12]

Error in pop() method. 

>>>list1=[2,4,6,8,10,12,14]
>>>print(list1.pop(16))

O/P
print(list1.pop(16))
IndexError:pop index out of range.

Next Example 

Programmer=['Tania,'kodlog','Tabia']
Programmer.pop(1)
Print (Programmer)

OUTPUT 
['Tania','Tabia']

Example 

Programmer=['Tania','Kodlog','Tabia']
X=Programmer.pop(1)
Print (X)
 
OUTPUT 
['Kodlog']

 

100 points
4