Jika Anda sebelumnya pernah mempelajari Tuple, maka sekarang kita mempelajari nametuple. Nametuple adalah tuple yang,..eh, memiliki nama tentu saja.

from collections import namedtuple

color = namedtuple('RGB',['red','green','blue'])
color = RGB(55,255,0)
white = RGB(255,255,255)

# Component red in white ?
print(white.red) 
# 255

Last modified: September 23, 2020

Author

Comments

Write a Reply or Comment

Your email address will not be published.