0

I'm still a beginner in learning python but I came across this function :

def  show_skills (name , *skills ,**skillswithprogress) :
   
   print (f'hello {name} \n skills without progress is :')
   for skill in skills :
      print (f'-{skills}')
   print ('skills with progress is :')
   for skill_key , skills_value in skillswithprogress.items():
      print(f'-{skill_key} =>{skills_value}')


show_skills('H', python = '95%',css = '95%')

and the output for it is as follows:

hello H 
 skills without progress is :
skills with progress is : 
-python =>95%
-css =>95%

Can anyone explain explain why did [python = '95%',css = '95%'] get treated like that, not as *skills ?

petezurich
  • 9,280
  • 9
  • 43
  • 57
  • 2
    `**skillswithprogress` collects keyword parameters. `*skills` collects non-keyword (positional) parameters. (thanks chepner) – CryptoFool Nov 28 '22 at 19:08
  • in you case both are keyword arguments so both will be considered as `skillswithprogress`. – deep adeshra Nov 28 '22 at 19:09
  • 1
    @CryptoFool The term you are looking for is *keyword arguments*, not "named parameters". (Parameters and arguments are quite distinct concepts.) – chepner Nov 28 '22 at 19:10
  • Arguments are the *value* you provide to a function *call*. Parameters are the names you provide in a function *definition*. – chepner Nov 28 '22 at 19:44

1 Answers1

0

It is the concept of *args and **kwargs

*args is the list or tuple

**kwargs is the dictionary

you put the parameter for the function as like show_skills('H', python = '95%',css = '95%')

would be python='95%', css='95%' => {python:'95%', css:'95%'}