I found this page very usefull and complete about the types that are most used in Python, so feel free to check it if you still have doubts about the types in Python 3.
Boolean
The first of the types are the boolean. This types are used to evaluate simple true or false statements for control loops. They can take two different values True or False, and almost all the times are result of a logic operation like a comparison between two values.
Numbers
Numbers are divided in two basic types:
- Integers: They are the set of the Integer numbers (Z). They can be of any size, thus long type doesn’t exist any more. They are used for cycles, for example in a for cycle we don’t use floating point numbers, we can’t execute half a cycle or a cycle and a third.
- Float: They complete the set of the Real numbers, so we have floating point numbers, with up to 15 decimals of precision.
There are ways to convert an int into a float, most of the time is just by adding a cast. For example:
>>>int(2.5)
2
Another important operator is the floor division //, wich gives us the integer result of a division , instead of giving the floating point.
Strings
Strings are the way Python manages text, they are sequences of Unicode text, and they are asigned by using “”; they are much like arrays of characters, so they share some functions.
Lists
Lists are very usefull ways of saving sets of different types. Lists can contain any number of elements and they can be texts or numbers. They can be modified by many means. And normally they are used to store data and then use it againg.
For loops are used to go trough the elements inside a list. And there are many ways to add elements or to rearange them. The way to create them is to use the name of the list and then typing all the elements in it inside brackets […].
Tupples
Tupples are much like lists, but they are created by encasing the elements in parenthesis instead of brackets (…). And have the peculiarity that they cannot be modified once created, they are much like read-only lists.
What are they goof for then? Well since they are write protected, you can use a set of data that must never be modified even by mistake. They also tend to be faster when they are processed by the computer. And they are able to be used as dictionary keys, wich we don’t want to get modified.
Dictionary
A Dictionary in Python can be imagined as a bidimensional array, in wich every value in a column has a value in the next column. Much like actual language dictionary, in a dictionary you have a key word and you have a meaning for that, so it is in Python’s Dictionary, you have keys and you have a meaning assosiated to it.
In order to create them we use keys and we use colon to stablish the key-meaning realtionship:
{ key : meaning, other key : next meaning}
This is for my #Mastery9 of my #TC1014.