10 Working with Type Matching and Annotations
This chapter will look at how we can work with data structures that have a variety of data types. This often means inspecting the type of an attribute, an element of a tuple, or a value in a dictionary.
In previous chapters, we’ve avoided spending too much time on data validation considerations. In this chapter, we’ll look closely at validating input values to be sure they conform to expected data types and value ranges.
This data validation is a kind of type-checking. It validates a narrower domain of values than the very broad classes of integer or string. The application must check the values of objects to be sure they’re valid for the intended purpose.
Some data structures like JSON or XML documents ...
Get Modern Python Cookbook - Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.