Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

270
Vistas
How to translate JavaScript ('object') into Python?

I am working on converting some JavaScript code into Python.

There is an if condition in the JavaScript that looks something like: if (typeof f === 'object') and then a series of actions are taken if this condition evaluates to true.

In this case f would be something like: f = { 'fields': ["user_id", "date_started", "date_ended"] }

In this case f is a dict, but it might not always be the case.

I know that in JavaScript nearly everything is considered an object. What would be the equivalent constraint to object in Python?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

In JavaScript typeof f == 'object' is true when all of the following is not true:

  • f is undefined: there is no equivalent in Python
  • f is a number, bigint or boolean: in Python this is an instance of float or int. As bool is a subclass of int, it is included.
  • f is a string: in Python this is an instance of str
  • f is a symbol: there is no equivalent in Python
  • f is a function: in Python you can use callable to detect this

Caveat: typeof null == 'object' is true, so in Python None should pass the equivalent test.

So this brings us to the following test in Python:

if not (callable(f) or isinstance(f, (int, float, str))):
    # it is an "object"
about 4 years ago · Juan Pablo Isaza Denunciar

0

you can use type method for getting type of variables in python:

if (type(f) is dict)

Actually, js objects in python are dictionaries! you can see more details from this link.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda