Skip to content

Instantly share code, notes, and snippets.

@einnar82
Last active January 6, 2020 00:04
Show Gist options
  • Save einnar82/a5d401532a7bca5bebabc5b2d95fc23a to your computer and use it in GitHub Desktop.
Save einnar82/a5d401532a7bca5bebabc5b2d95fc23a to your computer and use it in GitHub Desktop.
Spread operator in Python (Part 2)
from person import Person
class HR(Person):
def getFullName(self):
return "Mr/Ms " + self.firstName + " " + self.lastName
def getKeywordedArgs(self, **kwargs):
# The double asterisk form is used to pass a keyworded, variable-length argument list.
a, b = kwargs
return kwargs[a]
def getUnkeywordedArgs(self, *args):
# The single asterisk form is used to pass a non-keyworded, variable-length argument list
two, three, noValue = args
return args[two]
hr = HR('John', 'Doe', 28)
kwargs = {
'name': 'sample',
'age': 1
}
args = [1, 2, 3]
print(hr.getFullName()) # Mr/Ms John Doe
print(hr.getKeywordedArgs(**kwargs)) # sample
print(hr.getUnkeywordedArgs(*args)) # 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment