0
*c (python)
Hi everyone, I just wandering what is that mean when declaring operator as *c # nums=[a,b*c]
3 Respuestas
+ 12
@Denis U forgot comma (,) between b & *c...
*c is an optional parameter...
which means it can take any number of parameters passed to it ...
for eg:-
def nums (a,b,*c) :
return (*c)
print(nums(1,2,3,4,5))
this will output : 345
here a & b are mandatory parameters so 1st two passed parameters will be given to them
since c is an optional parameter rest passed parameters will be given to c...
a=1
b=2
c=rest... i.e. c=3,4,5
0
* is a multiplication operator, nums is a list with two elements, one is a, and other is the product of b, and c
If a = 1, b = 2, and c = 3
nums = [1, 6]
0
Thanks a lot, it’s very helpful!
@DT, you’re right, I forgot comma! Appreciate your understanding and answer!