Skip to content

Commit 4dae5d1

Browse files
authored
Merge pull request #7 from PythonistaCafe/add-named-tupled-example
feat(List): adding named tuple example
2 parents c7ed1b8 + 7535b3d commit 4dae5d1

File tree

1 file changed

+10
-0
lines changed
  • 1. Standard Python/Lists & Tuples

1 file changed

+10
-0
lines changed

1. Standard Python/Lists & Tuples/main.py

+10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@
3030
for item in tup:
3131
print(item)
3232

33+
# Named tuples examples
34+
from collections import namedtuple
35+
36+
color = namedtuple('color', ['hue', 'saturation', 'brightness'])
37+
38+
p = color(170, 20, 50)
39+
if p.hue > 100: # instead of p[0]
40+
print('do something')
41+
if p.saturation <= 50: # instead of p[1]
42+
print('do something')
3343

3444
# Apply the same behaviour to all items of a list - here add 2 to each number
3545
list_of_int = [1, 2, 3, 4, 5, 6, 7, 8, 9]

0 commit comments

Comments
 (0)