no way to compare when less than two revisions
Différences
Ci-dessous, les différences entre deux révisions de la page.
Révision précédenteDernière révision | |||
— | teaching:progappchim:collection_namedtuple_exemple [2021/01/22 11:21] – [Exemple d'utilisation de namedtuple] villersd | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | ====== Exemple d' | ||
+ | |||
+ | L' | ||
+ | |||
+ | |||
+ | <code python namedtuple-chemical_elements-01.py> | ||
+ | # | ||
+ | # -*- coding: utf-8 -*- | ||
+ | |||
+ | from collections import namedtuple | ||
+ | |||
+ | ChemEl = namedtuple(' | ||
+ | # same as defining a class for elements | ||
+ | |||
+ | hydrogen = ChemEl(' | ||
+ | helium = ChemEl(' | ||
+ | |||
+ | print(hydrogen.atomic_weight) | ||
+ | print(hydrogen.symbol) | ||
+ | |||
+ | print(hydrogen, | ||
+ | print(helium) | ||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Références ===== | ||
+ | Module collections : | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||