Skip to content

Commit 0659dd7

Browse files
author
Sebastian Muthwill
committed
adds named_tuple
1 parent db4b9f8 commit 0659dd7

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Playground to test python concepts and standard functionalities
44
## Python functionalities
55
[enumeration](enumeration.py)
66
[list_comprehension](list_comprehension.py)
7-
7+
[named_tuple](named_tuple.py)

named_tuples.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Named tuples can be used to return values e.g. from a function
2+
in a structured way.
3+
This has the benefit, the data can be accessed by the attribute.
4+
5+
"""
6+
7+
from collections import namedtuple
8+
9+
Geoposition = namedtuple('Geoposition', ['latitude', 'longitude'])
10+
11+
position = Geoposition('49.12345', '1.12345')
12+
print(position)
13+
print(position.latitude)
14+
print(position.latitude)

0 commit comments

Comments
 (0)