Class accepts varying arguments Python -
how class take varying arguments? example, if had class this
class shape(object): def __init__(self, sides): self.sides = sides
if phone call shapes(3), sides 3 aka triangle.
how this: if wanted phone call shape() no arguments, automatically create shape() have self.sides = 4. aka square
make default argument:
class shape(object): def __init__(self, sides=4): self.sides = sides
python python-3.x
No comments:
Post a Comment