edmontonpy.com
@edmontonpy
edmontonpy.slack.com
Matthew Petersen
NEXT MEETUP ON TUESDAY, OCTOBER 9TH DUE TO THANKSGIVING
Keyword-only parameters in Python 3.x
Use * in function parameter lists to force the use of keyword arguments for certain parameters:
Code
class Coordinate:
def __init__(self, *, latitude=0, longitude=0):
self.latitude=latitude
self.longitude=longitude
...
Coordinate(34, 37)
TypeError: __init__() takes 1 positional argument but 3 were given
Coordinate(latitude=34, longitude=37)
Coordinate(longitude=37, latitude=34)