0

*c (python)

Hi everyone, I just wandering what is that mean when declaring operator as *c # nums=[a,b*c]

19th Feb 2018, 6:44 AM
Denis
Denis - avatar
3 RĂ©ponses
+ 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
19th Feb 2018, 8:41 AM
🌛DT🌜
🌛DT🌜 - avatar
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]
19th Feb 2018, 7:20 AM
Ravi Chandra Enaganti
Ravi Chandra Enaganti - avatar
0
Thanks a lot, it’s very helpful! @DT, you’re right, I forgot comma! Appreciate your understanding and answer!
19th Feb 2018, 11:18 AM
Denis
Denis - avatar