Created
July 18, 2020 17:14
-
-
Save kshirsagarsiddharth/d5f5a814867e39747f9941cece20cbe9 to your computer and use it in GitHub Desktop.
using tuple operations on a namedtuple
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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