Skip to Content
Secret Recipes of the Python Ninja
book

Secret Recipes of the Python Ninja

by Cody Jackson
May 2018
Intermediate to advanced content levelIntermediate to advanced
380 pages
9h 37m
English
Packt Publishing
Content preview from Secret Recipes of the Python Ninja

Named tuples

  1. namedtuples_sales.py, below, will create a restaurant receipt, indicating the store ID, sales date, amount, and number of guests:
    • The line 9 shows the creation of the named tuple. The first argument to the named tuple is the name of the tuple subclass. The remaining arguments are the fields for the tuple.
    • The lines 10 and 11 create two different restaurants, showing receipts for the same day.
    • The line 12 and line 13 show how to access the individual fields within the different tuples using the field names rather than the indexes.
    • The line 14 shows that these restaurant instances are, indeed, actual tuples. They can be iterated ...
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

The Expanding World of Python

The Expanding World of Python

Dane Hillard

Publisher Resources

ISBN: 9781788294874Supplemental Content