Skip to Content
Python 3 Object-Oriented Programming - Third Edition
book

Python 3 Object-Oriented Programming - Third Edition

by Dusty Phillips
October 2018
Beginner to intermediate
466 pages
12h 2m
English
Packt Publishing
Content preview from Python 3 Object-Oriented Programming - Third Edition

Named tuples

So, what do we do when we want to group values together, but know we're frequently going to need to access them individually? There are actually several options. We could use an empty object, as discussed previously (but that is rarely useful, unless we anticipate adding behavior later), or we could use a dictionary (most useful if we don't know exactly how much data or which specific data will be stored), as we'll cover in a later section. Two other options are named tuples, which we'll discuss here, and dataclasses, in the next section.

If we do not need to add behavior to the object, and we know in advance which attributes we need to store, we can use a named tuple. Named tuples are tuples with attitude. They are a great way ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python 3 Object-Oriented Programming - Second Edition

Python 3 Object-Oriented Programming - Second Edition

Dusty Phillips

Publisher Resources

ISBN: 9781789615852Supplemental Content