assign operator as variable ?

-- bj0rn BjornSteinarFjeldPettersen at gmail.com
Wed Jun 7 08:28:24 CEST 2006


s99999999s2003 at yahoo.com wrote:
> hi
> in python is there any way to do this
>
> op = "<"
> a = 10
> b = 20
> if a op b :
>    print "a is less than b"


s99999999s2... at yahoo.com wrote:
> hi
> in python is there any way to do this
>
> op = "<"
> a = 10
> b = 20
> if a op b :
>    print "a is less than b"

Will this work for you?:

import operator
op = operator.lt
a = 10
b = 20
if op(a, b):
    print "a is less than b"

-- bj0rn




More information about the Python-list mailing list