Skip to content

Instantly share code, notes, and snippets.

@kshirsagarsiddharth
Created July 18, 2020 17:14
Show Gist options
  • Select an option

  • Save kshirsagarsiddharth/d5f5a814867e39747f9941cece20cbe9 to your computer and use it in GitHub Desktop.

Select an option

Save kshirsagarsiddharth/d5f5a814867e39747f9941cece20cbe9 to your computer and use it in GitHub Desktop.
using tuple operations on a namedtuple
from collections import namedtuple
Bevrage = namedtuple('Bevrage',['name','color','type'])
tea = Bevrage('tea','brown','hot')
# printing length of tea object
print(len(tea))
# Output: 3
# unpacking the tea object
name,color,Type = tea
print(name,color,Type)
# Output: tea brown hot
# using indexing in tea object
print(tea[0])
# Output: tea
# unpacking the tea object
print(*tea)
# Output: tea brown hot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment