Last active
January 6, 2020 00:04
-
-
Save einnar82/a5d401532a7bca5bebabc5b2d95fc23a to your computer and use it in GitHub Desktop.
Spread operator in Python (Part 2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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