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 force a value to be within a range?

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

  1. Stack

    Stack Membro Participativo

    What is the most "pythonic" way to do this?

    x = some_value
    bounds = [lower_bound, upper_bound]

    if x < bounds[0]:
    x = bounds[0]
    if x > bounds[1]:
    x = bounds[1]

    Continue reading...

Compartilhe esta Página