나는 이렇게 학습한다/Algorithm & SQL

0124. Regular Ball Super Ball

daco2020 2023. 1. 24. 23:51
반응형

Create a class Ball. Ball objects should accept one argument for "ball type" when instantiated.

If no arguments are given, ball objects should instantiate with a "ball type" of "regular."

ball1 = Ball()
ball2 = Ball("super")
ball1.ball_type  #=> "regular"
ball2.ball_type  #=> "super"



Solution:

class Ball(object):
    def __init__(self, type: str = "regular") -> None:
        self._type = type

    @property
    def ball_type(self) -> str:
        return self._type


반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

0126. Over The Road  (0) 2023.01.27
0125. Counting sheep...  (0) 2023.01.25
0123. Check same case  (0) 2023.01.23
0122. The Feast of Many Beasts  (0) 2023.01.23
0121. esreveR  (0) 2023.01.21