17.12.2012 Views

Programmation PYTHON - Zenk - Security - Repository

Programmation PYTHON - Zenk - Security - Repository

Programmation PYTHON - Zenk - Security - Repository

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

178<br />

Éléments du langage<br />

DEUXIÈME PARTIE<br />

Représentation d’un objet<br />

>>> liste = [1, 2, 3, 4]<br />

>>> repr(liste)<br />

'[1, 2, 3, 4]'<br />

>>> eval(repr(liste))<br />

[1, 2, 3, 4]<br />

>>> eval(repr(liste)) == liste<br />

True<br />

Une classe peut implémenter le fonctionnement de repr en définissant une méthode<br />

__repr__.<br />

Voir aussi : str.<br />

round : round(nombre[, ndigits]) -> réel<br />

Permet d’arrondir un nombre en fonction de la précision ndigits, qui représente le<br />

nombre de chiffres après la virgule. ndigits est à 0 par défaut et peut être négatif.<br />

round renvoie toujours un réel (flottant). Un entier passé en paramètre est donc<br />

transformé en réel.<br />

Arrondis<br />

>>> round(4.5687645, 3)<br />

4.569<br />

>>> round(4.5687645, 0)<br />

5.0<br />

>>> round(4.5687645)<br />

5.0<br />

>>> round(5)<br />

5.0<br />

>>> round(567.897, -1)<br />

570.0<br />

set : set(iterable) -> objet de type set<br />

Renvoie une collection non ordonnée d’éléments. Le paramètre doit être un objet<br />

supportant les itérations.<br />

Création d’une collection<br />

>>> collection = set([1, 2, 3])<br />

>>> collection.pop()<br />

1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!