Function to take the minimum of 3 numbers

Ian Kelly ian.g.kelly at gmail.com
Sun Oct 9 19:56:20 EDT 2016


On Oct 9, 2016 2:57 PM, <breamoreboy at gmail.com> wrote:

On Sunday, October 9, 2016 at 2:41:41 PM UTC+1, BartC wrote:
> def min3(a,b,c):
>      if a<=b and a<=c:
>          return a
>      elif b<=a and b<=c:
>          return b
>      else:
>          return c

The Pythonic way

if b >= a <= c:
    ...


Better:

if a <= b <= c:
    ...

Using consistent operators is not required but is easier to read and less
confusing.



More information about the Python-list mailing list