Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset
Comments Off

Python: Exemple d’utilisation de module operator

 module
{filelink=16854}

import operator # Importer le module operator
 
sequence = 1, 2, 4
 
"""
 Ci dessous exemple de certaine méthode
 du module operator
"""
print "Addition", "=>", reduce(operator.add, sequence)
print "Soustractionb", "=>", reduce(operator.sub, sequence)
print "Multiplication", "=>", reduce(operator.mul, sequence)
print "Division", "=>", reduce(operator.div, sequence)
print "Contacaténation", "=>", operator.concat("allo", "egg")
print "Sous séquence", "=>", operator.getitem(sequence, 2)
print "indexOf", "=>", operator.indexOf(sequence, 2)
print "Répétition d'une séquence", "=>", operator.repeat("allo", 5)
print "sequenceIncludes", "=>", operator.sequenceIncludes(sequence, 3)
 
"""
Addition => 7
Soustractionb => -5
Multiplication => 8
Multiplication => 0
Contacaténation => alloegg
Sous séquence => 4
indexOf => 1
Répétition d'une séquence => alloalloalloalloallo
sequenceIncludes => False
 
"""

Livres Sur ce Sujet

----------------------------------------------------------------------------

Comments are closed.