[Tutor] conditionals or comparison or expressions terminology

Peter Otten __peter__ at web.de
Wed Feb 5 10:32:08 CET 2014


Ian D wrote:

Ian, please answer to the list, not me in private. Thank you.

> Most of this makes sense except for the c(a<=b)
> also 
> if c(a<=b)
>  
> It is the c(...) syntax that I don't understand.
>  
> I dont recall seeing a statement like this.

c is just an arbitrary function, I put in the three dots as a placeholder 
for the actual arguments. A concrete example would be

# python2: use raw_input(), not input()
a = float(input("enter a float "))
b = float(input("enter another float "))

if abs(a - b) > 1.0:
    print("Your numbers are more than 1.0 apart.")

Here 

abs(a-b) > 1.0

is the conditional expression. It is in turn built of the comparison

x > 1.0

where x

is the function call 

abs(z)

where z is the arithmetic expression

a - b

PS: Fun fact: three dots may occur in actual Python code:

>>> def f(x): return x
... 
>>> f(...) # python 3 only
Ellipsis

The only place I know where this is commonly used is the numpy library:

>>> import numpy
>>> a = numpy.array(range(1, 5)).reshape((2,2))
>>> a
array([[1, 2],
       [3, 4]])
>>> a[0]
array([1, 2])
>>> a[...,1] # python 2 and 3
array([2, 4])




More information about the Tutor mailing list