🌐
W3Schools
w3schools.com › python › ref_list_pop.asp
Python List pop() Method
Python Examples Python Compiler ... Interview Q&A Python Bootcamp Python Training ... The pop() method removes the element at the specified position....
🌐
Mimo
mimo.org › glossary › python › pop()
Python Pop Method: Essential Data Manipulation techniques
In Python, pop() is a list method that removes and returns an element of a list. With an argument, pop() removes and returns the item at the specified index (starting from 0).
Discussions

list.pop and list.pop()
Python can't know this is a mistake. list.pop on its own is perfectly valid syntax. This gives you access to the pop method itself, which you might want for any number of reasons, such as passing it as a callback to another function. Now, a good linter will certainly see that you didn't do anything with that reference, and show a warning on that basis. But by itself this is not an error. More on reddit.com
🌐 r/learnpython
17
3
June 27, 2024
I don't think I understand what the .pop() method does on a list....
You shouldn't modify the list while iterating over it. It leads to weirdness like this. More on reddit.com
🌐 r/learnpython
9
3
March 2, 2021
🌐
Hyperskill
hyperskill.org › university › python › pop-in-python
Pop() in Python
October 14, 2025 - The pop() method, in Python is a built in function that is utilized to delete an element from a list at an index.
🌐
Programiz
programiz.com › python-programming › methods › list › pop
Python List pop()
The pop() method returns the item present at the given index. This item is also removed from the list. # programming languages list languages = ['Python', 'Java', 'C++', 'French', 'C']
🌐
DataCamp
datacamp.com › tutorial › python-pop
How to Use the Python pop() Method | DataCamp
July 31, 2024 - I write practical, industry-focused ... impact, helping professionals turn data into confident decisions. The pop() method removes and returns n element from lists or dictionaries....
🌐
DigitalOcean
digitalocean.com › community › tutorials › pop-python
How to Use `.pop()` in Python Lists and Dictionaries | DigitalOcean
July 24, 2025 - Python’s .pop() method is a powerful and flexible built-in function that allows you to remove and return elements from both lists and dictionaries. This method is especially useful in scenarios where you need to both extract and delete items in a single, efficient operation.
🌐
Simplilearn
simplilearn.com › home › resources › software development › pop in python: an introduction to pop function with examples
Pop in Python: An Introduction to Pop Function with Examples
November 13, 2025 - Pop in Python is a pre-defined, in-built function. Learn pop function's ✓ syntax ✓ parameters ✓ examples, and much more in this tutorial. Start learning now!
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-list-pop-method
Python List pop() Method - GeeksforGeeks
4 days ago - Python · a = [10, 20, 30, 40] val = a.pop() print(val) print(a) Output · 40 [10, 20, 30] Explanation: a.pop() removes and returns the last element of the list and removed value is stored in val.
Find elsewhere
🌐
freeCodeCamp
freecodecamp.org › news › python-pop-how-to-pop-from-a-list-or-an-array-in-python
Python .pop() – How to Pop from a List or an Array in Python
March 1, 2022 - And remember, pop() returns the item that has been removed. This enables you to store it in a variable, like you saw in the previous section. #list of programming languages programming_languages = ["Python", "Java", "JavaScript"] #remove first item and store in a variable programming_language = programming_languages.pop(0) #print updated list print(programming_languages) #print the value that was removed from original list print(programming_language) #output #['Java', 'JavaScript'] #Python
🌐
Analytics Vidhya
analyticsvidhya.com › home › understanding python pop() method
Understanding Python pop() Method
October 12, 2024 - The pop() method in Python works by directly altering the list in place and returning the element it removes. This method provides flexibility in removing elements either by specifying their position in the list or by defaulting to the last element.
🌐
iO Flood
ioflood.com › blog › python-pop
Python Pop() Method: Complete Guide
February 6, 2024 - Think of Python’s pop method as a skilled magician – making elements disappear from your data structures with a simple command. It’s a powerful tool that can simplify your data manipulation tasks significantly. In this guide, we’ll walk you through the process of mastering the pop method in Python, from its basic usage to more advanced techniques.
🌐
Scaler
scaler.com › home › topics › python list pop() method
Python List pop() Method - Scaler Topics
February 23, 2024 - The pop() function in Python is a pre-defined, inbuilt function in Python lists that removes an item at a specific index given as the argument to the pop() function. By default, it removes the last item from the list if no argument is given ...
🌐
Codecademy
codecademy.com › docs › python › lists › .pop()
Python | Lists | .pop() | Codecademy
May 26, 2025 - The .pop() method in Python removes an element from a list at a specified index and returns that element. The .pop() method directly modifies the original list by removing the element at the given position.
🌐
Unstop
unstop.com › home › blog › python pop() function | list & dictionaries (+code examples)
Python pop() Function | List & Dictionaries (+Code Examples)
November 11, 2024 - The pop() function in Python removes and returns an element from a list or dictionary based on the specified index (or key) or defaults to the last item.
🌐
freeCodeCamp
freecodecamp.org › news › pop-function-in-python
Pop Function in Python
January 29, 2020 - The method pop() removes and returns the last element from a list. There is an optional parameter which is the index of the element to be removed from the list. If no index is specified, a.pop() removes and returns the last item in the list.
🌐
W3Schools
w3schools.com › python › ref_dictionary_pop.asp
Python Dictionary pop() Method
Tutorial: Python Dictionary · Tutorial: Remove Dictionary Items · Method: popitem() Method: clear() Keyword: del · ❮ Dictionary Methods · ★ +1 · Sign in to track progress · REMOVE ADS · PLUS · SPACES · GET CERTIFIED · FOR TEACHERS · BOOTCAMPS · CONTACT US ·
🌐
DEV Community
dev.to › lisw05 › what-does-pop-stand-for-why-does-python-use-it-to-mean-removing-elements-2l7n
What does pop stand for? Why does Python use it to mean removing elements? - DEV Community
March 13, 2025 - Over time, the method was generalized to work with any index in the list. pop stands for "pop off" or "pop out", meaning to remove or extract something. Python uses pop to mean removing elements because it aligns with the terminology of stack ...
Top answer
1 of 4
138

The pop method of dicts (like self.data, i.e. {'a':'aaa','b':'bbb','c':'ccc'}, here) takes two arguments -- see the docs

The second argument, default, is what pop returns if the first argument, key, is absent. (If you call pop with just one argument, key, it raises an exception if that key's absent).

In your example, print b.pop('a',{'b':'bbb'}), this is irrelevant because 'a' is a key in b.data. But if you repeat that line...:

b=a()
print b.pop('a',{'b':'bbb'})
print b.pop('a',{'b':'bbb'})
print b.data

you'll see it makes a difference: the first pop removes the 'a' key, so in the second pop the default argument is actually returned (since 'a' is now absent from b.data).

2 of 4
31

So many questions here. I see at least two, maybe three:

  • What does pop(a,b) do?/Why are there a second argument?
  • What is *args being used for?

The first question is trivially answered in the Python Standard Library reference:

pop(key[, default])

If key is in the dictionary, remove it and return its value, else return default. If default is not given and key is not in the dictionary, a KeyError is raised.


The second question is covered in the Python Language Reference:

If the form “*identifier” is present, it is initialized to a tuple receiving any excess positional parameters, defaulting to the empty tuple. If the form “**identifier” is present, it is initialized to a new dictionary receiving any excess keyword arguments, defaulting to a new empty dictionary.

In other words, the pop function takes at least two arguments. The first two get assigned the names self and key; and the rest are stuffed into a tuple called args.

What's happening on the next line when *args is passed along in the call to self.data.pop is the inverse of this - the tuple *args is expanded to of positional parameters which get passed along. This is explained in the Python Language Reference:

If the syntax *expression appears in the function call, expression must evaluate to a sequence. Elements from this sequence are treated as if they were additional positional arguments

In short, a.pop() wants to be flexible and accept any number of positional parameters, so that it can pass this unknown number of positional parameters on to self.data.pop().

This gives you flexibility; data happens to be a dict right now, and so self.data.pop() takes either one or two parameters; but if you changed data to be a type which took 19 parameters for a call to self.data.pop() you wouldn't have to change class a at all. You'd still have to change any code that called a.pop() to pass the required 19 parameters though.