程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Confused Xiaobai for a long time - why do Python lists and dictionaries have asterisks (* *)?

編輯:Python

Hey, everyone, good duck , I'm a panda

Today, let's learn why Python Lists and dictionaries are preceded by asterisks ()?**


what are you having? python I won't answer the related error report 、 Or source code information / Module installation / Women's clothing bosses are proficient in skills You can come here :(https://jq.qq.com/?_wv=1027&k=2Q3YTfym) perhaps +V:python10010 Ask me

Python in , Single star * And the double star ** Except as “ ride ” and “ power ” Outside the numeric operator , Still on the list 、 Tuples 、 Dictionary plays an important role in the operation of .

One 、 list (list)、 Tuples (tuple) Preceded by an asterisk *

The asterisk in front of the list is used to untie the list (unpacke) Into multiple independent parameters , Passing in functions .

def add(a, b):
return a + b
data = [7, 8]
print(add(*data)) # 15
python Learning exchange group :660193417###
import numpy as np
print(np.arange(3,6)) # [3 4 5]
list2 = [3, 6]
print(np.arange(*list2)) # [3 4 5]

Two 、 Dictionaries (dict) Preceded by two asterisks **

Add two asterisks in front of the dictionary , Is to unpack the dictionary into independent elements as formal parameters .

def add(a, b):
return a + b
data = {
'a':7, 'b':8}
print(add(**data)) # 15

Today's knowledge point is like this , I hope I'm studying by myself python You have helped ~

I'm a panda , See you in the next article (*◡‿◡)


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved