Skip to content

Commit

Permalink
one more example
Browse files Browse the repository at this point in the history
  • Loading branch information
bast committed Sep 12, 2024
1 parent 33cfffe commit 100fafa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions content/refactoring/using-namedtuple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import math
from collections import namedtuple


def surface_area(radius: float) -> float:
return 4.0 * math.pi * radius**2


Moon = namedtuple("Moon", ["name", "radius", "contains_water"])


europa = Moon(name="Europa", radius=1560.8, contains_water=True)

print(europa)
print(f"Surface area (km^2) of {europa.name}: {surface_area(europa.radius)}")

0 comments on commit 100fafa

Please sign in to comment.