Python’s * and ** operators aren’t just syntactic sugar. When calling a function, the * operator can be used to unpack an iterable into the arguments in the function call: Asterisks for unpacking into function call The Python core developers have continued to add new abilities to these operators over the last few years and it’s easy to overlook some of the newer uses of * and **.
#What does for do in python code
![what does for do in python what does for do in python](https://d1zx6djv3kb1v7.cloudfront.net/wp-content/media/2021/11/what.jpg)
Using * to unpack iterables into a list/tuple.Using * to capture items during tuple unpacking.Using * to accept keyword-only arguments.Using * and ** to capture arguments passed into a function.Using * and ** to pass arguments to a function.Two of the uses of * are shown in that code and no uses of ** are shown. So I’m not talking about multiplication and exponentiation: When I discuss * and ** in this article, I’m talking about the * and ** prefix operators, not the infix operators. named arguments), I’d recommend reading my article on keyword arguments in Python first. If you’re newer to Python and you’re not yet familiar with keyword arguments (a.k.a. So if you learned * and ** back in the days of Python 2, I’d recommend at least skimming this article because Python 3 has added a lot of new uses for these operators.
![what does for do in python what does for do in python](https://www.askpython.com/wp-content/uploads/2019/07/python-user-input.png)
The * and ** operators have grown in ability over the years and I’ll be discussing all the ways that you can currently use these operators and noting which uses only work in modern versions of Python. I’d like to discuss what those operators are and the many ways they’re used. These two operators can be a bit mysterious at times, both for brand new programmers and for folks moving from many other programming languages which may not have completely equivalent operators. There are a lot of places you’ll see * and ** used in Python.