[Python] How to check whether a variable is a class or not?

Discussão em 'Python' iniciado por Stack, Fevereiro 16, 2025.

  1. Stack

    Stack Membro Participativo

    I was wondering how to check whether a variable is a class (not an instance!) or not.

    I've tried to use the function isinstance(object, class_or_type_or_tuple) to do this, but I don't know what type a class would have.

    For example, in the following code

    class Foo:
    pass

    isinstance(Foo, **???**) # i want to make this return True.


    I tried to substitute "class" with ???, but I realized that class is a keyword in python.

    Continue reading...

Compartilhe esta Página