Python中,单星号 * 和双星号 ** 除了作为“乘”和“乘方”的数值运算符外,还在列表、元组、字典的操作中有看到,下面对其进行解释:

    单星号 *
    单星号 * 用于对列表LIST或元组tuple中的元素进行取出(unpacke)。例如,np.arange函数需要独立的开始和停止参数:

import numpy as np
print(np.arange(3,6))
输出:
[3, 4, 5]

采用 * 可将列表或元祖中的元素直接取出,作为arange的上下限:

import numpy as np
LIST = [3, 6]
print(np.arange(*LIST))
输出:
[3, 4, 5]

    双星号 **
    双星号 ** 可将字典里的“值”取出

def parrot(voltage, state=‘a stiff’, action=‘voom’):
   … print “-- This parrot wouldn’t”, action,
   … print “if you put”, voltage, “volts through it.”,
   … print “E’s”, state, “!”
   …
   d = {“voltage”: “four million”, “state”: “bleedin’ demised”, “action”: “VOOM”}
   parrot(**d)

输出:
– This parrot wouldn’t VOOM if you put four million volts through it. E’s bleedin’ demised !