16
Named Tuples
from collections import namedtuple
Coordinate = namedtuple("Coordinate", "longitude latitude")
location = Coordinate(90, 37.5)
print("location:", location)
print(location.longitude, location.latitude)
For ... Else
for letter in 'foo':
print(letter)
else:
print("All letters have been printed")
for letter in 'foo':
print(letter)
if letter == 'o':
break
else:
print("Letters have been printed")
enums with the Enum module
from enum import Enum
Season = Enum('Season', 'winter summer spring autumn')
print(Season.summer.name)
print(Season.summer.value)
class Season(Enum):
winter = 1
summer = 2
spring = 3
autumn = 4
print(Season.winter.name)
print(Season.winter.value)