Reputation: 334
what does below code snippet initialization indicates ? how does it work ? how this variable assignment operates in python ?
def set_action_delays(
self,
enabled: bool = False,
like: int = None,
comment: int = None,
follow: int = None,
unfollow: int = None,
story: int = None,
randomize: bool = False,
random_range_from: int = None,
random_range_to: int = None,
safety_match: bool = True,
):
Upvotes: 1
Views: 49
Reputation: 697
These are "key arguments" also called "named arguments". If you are more familiar with other languages, where there are only "positional arguments" this def call would have same effect as your code, ie. you can use named on positioned arguments in python:
set_action_delays(self, False, None, None, None, None, None, False, None, None, True)
Upvotes: 0
Reputation: 5237
They are default parameter values: https://www.w3schools.com/python/gloss_python_function_default_parameter.asp
For instance, looking at safety_match: bool = True
: the default value would be set to True
in the case that the function is called without the argument.
The int
, bool
, etc are type hints:
https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html
Upvotes: 2