Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

121
Visualizações
"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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda