1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] How does multiplication work with a comparison? a*(b<c) [duplicate]

Discussão em 'Python' iniciado por Stack, Outubro 7, 2024.

  1. Stack

    Stack Membro Participativo

    I am a novice programmer and I am developing in PySimpleGui. I was reviewing the section on simulated tables that can be cycled through with the arrow keys.

    However, there is a portion of code that, although I "deduce" what it does, I don't understand how it works.

    Program: https://docs.pysimplegui.com/en/latest/cookbook/ecookbook/elements/tables/simulated-tables/

    Here is the part of the code:

    if event.startswith('Down'):
    r = r + 1 * (r < MAX_ROWS-1) # I don't understand this multiplication


    I understand that this helps to avoid generating an overflow error, which is why r takes a maximum of values less than 4 so that in the worst case it goes from r=3 to r=4. However, assuming its behavior, I do not fully understand the operation since if r=0, the operation would result in: r = 0 + 1 * (0 < 4), r=0. I don't understand. Obviously I'm not seeing something.

    Continue reading...

Compartilhe esta Página