PythonCookbook で述べたよう*
に、タプルの前に追加できます。ここでとは*
どういう意味ですか?
第1.18章。シーケンス要素への名前のマッピング:
from collections import namedtuple Stock = namedtuple('Stock', ['name', 'shares', 'price']) s = Stock(*rec) # here rec is an ordinary tuple, for example: rec = ('ACME', 100, 123.45)
同じセクションで、**dict
以下を示します。
from collections import namedtuple Stock = namedtuple('Stock', ['name', 'shares', 'price', 'date', 'time']) # Create a prototype instance stock_prototype = Stock('', 0, 0.0, None, None) # Function to convert a dictionary to a Stock def dict_to_stock(s): return stock_prototype._replace(**s)
**
ここでの の機能は何ですか?