Latest web development tutorials

Python comprend des exercices 49

Python 100 Li Python 100 Li

Titre: créer une fonction anonyme en utilisant lambda.

Analyse du programme: Aucun

Source Code:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

MAXIMUM = lambda x,y :  (x > y) * x + (x < y) * y
MINIMUM = lambda x,y :  (x > y) * y + (x < y) * x

if __name__ == '__main__':
    a = 10
    b = 20
    print 'The largar one is %d' % MAXIMUM(a,b)
    print 'The lower one is %d' % MINIMUM(a,b)

L'exemple ci-dessus sortie est:

The largar one is 20
The lower one is 10

Python 100 Li Python 100 Li