Home >Backend Development >Python Tutorial >Let's talk about adding an asterisk (**) before lists and dictionaries in Python
Why are there asterisks (**) in front of Python lists and dictionaries? The following article will talk to you about the reasons for adding an asterisk (**) before lists and dictionaries in Python. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
In Python, the single asterisk *
and the double asterisk **
are except for "multiplication" and "power" values. In addition to operators, it also plays an important role in the operations of lists, tuples, and dictionaries.
*
The effect of adding an asterisk in front of the list is to Unpack (unpacke) into multiple independent parameters and pass them into the function.
def add(a, b): return a + b data = [7, 8] print(add(*data)) # 15
import numpy as np print(np.arange(3,6)) # [3 4 5] list2 = [3, 6] print(np.arange(*list2)) # [3 4 5]
**
Add two asterisks in front of the dictionary to interpret the dictionary Open as an independent element as a formal parameter.
''' 学习中遇到问题没人解答?小编创建了一个Python学习交流QQ群:531509025 寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书! ''' def add(a, b): return a + b data = {'a':7, 'b':8} print(add(**data)) # 15
【Related recommendations: Python3 video tutorial】
The above is the detailed content of Let's talk about adding an asterisk (**) before lists and dictionaries in Python. For more information, please follow other related articles on the PHP Chinese website!