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

120
Vistas
Inline if else?

Here is part of code. I need to understand what this code do :

if instruction == "JOINT" or instruction == "ROOT":
    parent = joint_stack[-1] if instruction == "JOINT" else None
    joint = BvhJoint(words[1], parent)
    self.joints[joint.name] = joint

How to understand this line special ->

    parent = joint_stack[-1] if instruction == "JOINT" else None

Is this code equal with JS code:

if (instruction == "JOINT") {
    parent = joint_stack[-1];
} else {

}

?

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

0

The equivalent JS code would be:

   if (instruction == "JOINT") { 
        parent = joint_stack[-1];
    } else {
        parent = null;
    }

or more idiomatically:

    parent = instruction == "JOINT" ? joint_stack[-1] : null;

This ternary expression in Python:

joint_stack[-1] if instruction == "JOINT" else None

is the same as the JS ternary expression:

instruction == "JOINT" ? joint_stack[-1] : null
about 4 years ago · Juan Pablo Isaza Denunciar

0

 parent = joint_stack[-1] if instruction == "JOINT" else None

This will check the “instruction” is equal to “JOINT” if yes, last value of joint_stack array will be assigned to the parent, otherwise None

about 4 years ago · Juan Pablo Isaza Denunciar

0

The JS equivalent would be

const parent = (instruction === "JOINT")?joint_stack[-1]:null;

The shortcut to conditional expression was added to Python 2.5. See Does Python have a ternary conditional operator?

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