1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How to assign a variable in an IF condition, and then return it?

Discussão em 'Python' iniciado por Stack, Setembro 14, 2024.

  1. Stack

    Stack Membro Participativo

    def isBig(x):
    if x > 4:
    return 'apple'
    else:
    return 'orange'


    This works:

    if isBig(y): return isBig(y)


    This does NOT work:

    if fruit = isBig(y): return fruit


    Why doesn't the 2nd one work!? I want a 1-liner. Except, the 1st one will call the function TWICE.

    How to make it 1 liner, without calling the function twice?

    Continue reading...

Compartilhe esta Página