1. Description
*,nkw denotes the named keyword parameter, which is the name of the keyword parameter that the user wants to enter, defined by appending *, before nkw.
2. Role
Restricts the names of parameters communicated by the caller.
3. Examples
# Naming keyword parameters def print_info4(name, age=18, height=178, *, weight, **kwargs): ''' Print message function 4, add named keyword parameter :param name. :param age. :param height: :param weight: :param :param weight: :param kwargs: :param :param kwargs: :return: :param :return. ''' print('name: ', name) print('age: ', age) print('height: ', height) print('keyword: ', kwargs) print('weight: ', weight) print_info4('robin', 20, 180, birth='2000/02/02', weight=125)
Knowledge Point Expansion:
Keyword parameters
Variable parameters allow you to pass 0 or any number of parameters, which are automatically assembled into a tuple when the function is called, whereas keyword parameters allow you to pass 0 or any number of parameters with parameter names, which are automatically assembled into a dict inside the function.
Shaped as:
>>> def person(name,age,**kw): print("name:",name,"age:",age,"other:",kw) >>> person("bbj",23,city="hefei",habit="basketball") name: bbj age: 23 other: {'city': 'hefei', 'habit': 'basketball'} >>>
The keyword parameter as I understand it means that you can pass in countless self-named parameters when you call it, and the keyword here means that you name it yourself. All keyword arguments are automatically assembled into a dictionary.
to this article on the role of python named keyword parameter details of the article is introduced to this, more related to python named keyword parameter what is the use of content please search my previous articles or continue to browse the following related articles I hope you will support me more in the future!