Data types
What is a user defined data type:
This is a data type that is created by a programmer. They define how the computer stores, reads and operates on values stored in that data type.
What is a built in data type:
This has already been defined by the programming language.
What separates a built in data type from a User defined:
The fact that there is a predefined range of values that can be stored in ta variable a operations performed with that data type.
What are abstract data types:
What's the purpose of user defined data types:
Non composite and composite data types and how are they used in python. Some examples:
Non composite data types are also called primitive and can only store one element. Like an integer.
A good way to tell, is to think if you can iterate through each element in that variable then it's composite. Composite data types can store many elements in the variable, like a list and a string or type and record.
Example of non composite data types:
Enumerated data type - I first heard of this in game dev where you create an enumerated data type to hold all the possible values that a variable can be. In my case we'd use it for direction where when you press a key and the variable would return, right etc.
These values are not strings and are ordinal so they have an inherent value -its so that you can keep track of the next value and return the integer of the value when needed.
A pointer - this stores the memory location of another variable. This is a primitive data type.
A set - this is like a list but it's non indexable as the values do not have any order or structure and there can be no repeating values. It follows the principles of set theory. So when you have a set of numbers there no repeating values as there's no repeating numbers in a number line. You can manipulate the set using set theory like unions in a Venn diagram. This can be useful because you could see if there's only overlap between groups of data
Examples of Composite user-defined data types:
The record - so you want to organise different information for a book. The information you want to hold is the title, author and price. You could create a dictionary with values and a list. But this is complicated because you'd need a dictionary per book. So you could create a class and define a data type called book, and the data type has the values title, author and price. Then anytime you want to enter a new book you would call the class and write the title, author and price as parameters. And you can use the class name . Value to acess that value.
How to create my own user defined data type.
