“What features does Python support because it’s an object-oriented programming language?”
“Python supports a full range of features (like inheritance
“What do you have to do to get things done in Python?”
“To get things done in Python
“What do classes and inheritance make easy to do?”
“The classes and inheritance make it easy to express a program’s desired behavior through objects.”
“What else do classes and inheritance let you do?”
“They also let you to improve and expand functionality over time.”
“What does knowing how to write good classes enable?”
“Knowing how to write good classes enables you to write maintainable code.”
“What is Python’s built-in dictionary type useful for?”
“Python’s built-in dictionary type is useful for maintaining dynamic (situations where you need to do booking for an unexpected numbers of identifiers) internal state over the lifetime of an object.”
“What risk exists with dictionaries and related built-in types?”
“Dictionaries and their related built-in types are so easy to use that there’s a risk of overextending them and creating brittle code.”
“What is one solution to the dictionary overuse problem?”
“One solution to the above problem is to use a defaultdict instance to replace an inner dictionary and handle missing subjects.”
“What should you do if your classes have a complex array of built-in types?”
“If your classes have a complex array of built-in types like dictionaries
“What did Python’s built-in dictionary and tuple types make easy?”
“Python’s built-in dictionary and tuple types made it easy to keep adding layers to the internal bookkeeping.”
“How much nesting should you avoid with dictionaries?”
“However
“What should you do when internal bookkeeping gets complicated?”
“As soon as your internal bookkeeping gets complicated
“What can you then provide after breaking into classes?”
“You can then provide well-defined interfaces that encapsulate all your data.”
“What other benefit does this approach provide?”
“This approach also lets you create a layer of abstraction between your interfaces and your concrete implementations.”
“How many approaches to refactoring exist?”
“There are many approaches to refactoring.”
“What is extending tuples similar to?”
“Extending tuples longer and longer is similar to deepening layers of dictionaries.”
“When should you use another approach instead of tuples?”
“As soon as your tuples get bigger than a two-tuple
“What does the namedtuple type solve?”
“The namedtuple type in the collections module solves the problem mentioned above: it lets you define tiny
“How can namedtuple classes be created?”
“The classes mentioned above can be created with positional or keyword arguments.”
“How are namedtuple fields accessible?”
“The fields are accessible with named attributes.”
“What does having named attributes make easy?”
“Having named attributes makes it easy to move from a namedtuple to a class later if the requirements change (like if you need to support mutability or behaviors in the simple data containers).”
“What trade-off exists when breaking built-in types into classes?”
“Breaking built-in types into classes greatly increases the implementation size of a project
“Are there situations where namedtuple can do more harm than good?”
“Although there are good things about namedtuple
“Can you specify default argument values in namedtuple?”
“You can’t specify default argument values.”