[Python] Why use classes over a function that just returns an object? [duplicate]

Discussão em 'Python' iniciado por Stack, Março 7, 2025.

  1. Stack

    Stack Membro Participativo

    So I can make a function that does everything that I class can do (I think). So why would I ever use a class? (Yes this is just an example but you could also put like functions or anything else you want to into a dictionary/object for you JavaScripter's out there)

    class User:
    def __init__ (self, user_id):
    self.id = user_id

    user_1 = User("1")

    def makeUser(user_id):
    return {
    id:user_id,
    }

    user2 = makeUser("2")

    Continue reading...

Compartilhe esta Página