named tuples sowhat do we do when we want to group values togetherbut know we're frequently going to need to access them individuallywellwe could use an empty objectas discussed in the previous section (but that is rarely useful unless we anticipate adding behavior later)or we could use dictionary (most useful if we don' know exactly how many or which specific data will be stored)as we'll cover in the next section ifhoweverwe do not need to add behavior to the objectand we know in advance what attributes we need to storewe can use named tuple named tuples are tuples with attitude they are great way to group read-only data together constructing named tuple takes bit more work than normal tuple firstwe have to import namedtupleas it is not in the namespace by default thenwe describe the named tuple by giving it name and outlining its attributes this returns class-like object that we can instantiate with the required values as many times as we wantfrom collections import namedtuple stock namedtuple("stock""symbol current high low"stock stock("fb" high= low= the namedtuple constructor accepts two arguments the first is an identifier for the named tuple the second is string of space-separated attributes that the named tuple can have the first attribute should be listedfollowed by space (or comma if you prefer)then the second attributethen another spaceand so on the result is an object that can be called just like normal class to instantiate other objects the constructor must have exactly the right number of arguments that can be passed in as arguments or keyword arguments as with normal objectswe can create as many instances of this "classas we likewith different values for each the resulting namedtuple can then be packedunpackedand otherwise treated like normal tuplebut we can also access individual attributes on it as if it were an objectstock high symbolcurrenthighlow stock current remember that creating named tuples is two-step process firstuse collections namedtuple to create classand then construct instances of that class