Resolved: why we put an asterisk(*) in the line of code: plt.legend(*scatter.legend_elements())
Could you explain why we put an asterisk(*) before variable. What does the asterisk exactly do in the line of code in the picture below. Thank you
thanks for reaching out! In this case, the asterisk means unpacking. Basically, it gives us a list of the elements of the scatter.legend_elements(). So, for example if we have a list:
mylist = ["A", "B", "C", "D"]
print(*mylist) will result in
A B C D
It's the same logic for the legend elements in the scatter plot.
Hope this helps!