Last answered:

08 Nov 2022

Posted on:

07 Nov 2022

1

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

image.png

2 answers ( 1 marked as helpful)
Instructor
Posted on:

07 Nov 2022

0

Hi Thai,
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"]

then 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!

Best,
365 Eli

Posted on:

08 Nov 2022

0

Hi Elitsa,

Thank you for your quick response. I did some searching on the internet and I'm clearer now. Thank you.

Submit an answer