Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!