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

129
Views
"in" operator chaining ( True in [True] in [True] OUTPUT: False )

I'm trying to figure out in what order this code runs:

print( True in [True] in [True] )
False

even though:

print( ( True in [True] ) in [True] )
True

and:

print( True in ( [True] in [True] ) )
TypeError

If the first code is neither of these two last ones, then what?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

in is comparing with chaining there so

True in [True] in [True]

is equivalent to (except middle [True] is evaluated once)

(True in [True]) and ([True] in [True])

which is

True and False

which is

False

This is all similar to

2 < 4 < 12

operation which is equivalent to (2 < 4) and (4 < 12).

over 4 years ago · Santiago Trujillo Report

0

print( True in [True] in [True] )

This is actually interpreted as - True in [True] and [True] in [True] which gives you false because it becomes - True and False

print( ( True in [True] ) in [True] )

The ( True in [True] ) is checked first, so you get True in [True] which is True.

print( True in ( [True] in [True] ) )

The second part is checked, before the first because of parenthesis which changes the order, so it becomes - True in True. And True which is a boolean, is not a iterable, so you cannot use in, and then you get TypeError

over 4 years ago · Santiago Trujillo 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!