[Python] How to Set Default Argument of Class Method Equal to Class Attribute?

Discussão em 'Python' iniciado por Stack, Abril 17, 2025.

  1. Stack

    Stack Membro Participativo

    I have a class like:

    class Cheetah:
    def __init__(self):
    self.speed = 20
    def move(self, speed):
    ....


    How can I set the default value of speed in the method move to self.speed?

    I've tried speed = self.speed, but I get a syntax error.

    Continue reading...

Compartilhe esta Página