2024-04-20 13:25:24 发布
网友
例如,有人能给我解释一下下面第二行星号的用途吗?你知道吗
m = Basemap(projection='merc', llcrnrlon=lon.min(), urcrnrlon=lon.max(), llcrnrlat=lat.min(), urcrnrlat=lat.max()) x, y = m(*np.meshgrid(lat,lon))
这意味着它将在单个元素中“扩展”集合。你知道吗
所以,假设一个函数需要很多参数,并且在一个集合中有这些参数。由于无法传递集合本身(该集合将计为单个参数),因此使用*来扩展集合并将其作为单个参数传递给函数。你知道吗
*
从documentation:
An asterisk * denotes iterable unpacking. Its operand must be an iterable. The iterable is expanded into a sequence of items, which are included in the new tuple, list, or set, at the site of the unpacking.
这意味着它将在单个元素中“扩展”集合。你知道吗
所以,假设一个函数需要很多参数,并且在一个集合中有这些参数。由于无法传递集合本身(该集合将计为单个参数),因此使用
*
来扩展集合并将其作为单个参数传递给函数。你知道吗从documentation:
An asterisk * denotes iterable unpacking. Its operand must be an iterable. The iterable is expanded into a sequence of items, which are included in the new tuple, list, or set, at the site of the unpacking.
相关问题 更多 >
编程相关推荐