What are user defined types?
Sometimes the use of in-built data types / structures are not sufficient to represent the data you are working with. It is therefore necessary to construct your own data types/structures. User defined types can make programs much easier to code, read and debug.
Non-composite vs Composite types
Non composite types are user defined types that contain only one data type, for instance enumerators.
Composite data types are user defined types that contain more than one data type, for instance a record
Enumerators bind a group of names to constant values and are useful for things such as days of the weeks or months of the year,
Enumerators in Python
Enumerators were added to Python 3.4+
A pointer is a datatype that refers to a location in memory. It is a form of indirect referencing. Obtaining the value stored at the memory location is known as dereferencing.
Python does not use pointers, though many other languages (such as C) do. For a discussion why Python doesn’t use pointers, take a look at this article.
Records are composite data types that contain references to at least 1 other datatype within them. The advantage of records is that all related data is tied together in one place. They are incredibly useful and popular in many languages.
Sets are a composite data type that are unordered, iterable, mutable and contain no duplicate elements.
Python sets are in built and are incredibly useful for certain tasks where you need to compare 2 sets in some way.
The main functions are:
- Symmetric difference
Python Sets Tutorial
Python Sets have lots of useful methods that can be found here.
Create a function called months_between that finds out the number of months between 2 months
Create a list of zoo animals in records and print out the details of the animals in a headed table format.
Adapt challenge 2 so that the program asks the user to input some parameters(such as maximum height) and only prints out the relevant information.