Data Types and Operators
They are essential to make use of the [almost] full power of variables
Data Types
What are they and why would I care?
When you define a variable you choose its type by changing it's form , each data type has different properties for different cases. They are important since you can't use only 1 data type for everything.
Ok , but how you classify them?
The data types are the following string, int, float, boolean . Now I'll say a really short summary of what each of them is and used for
INT - comes from integer and it represent any number [they need to converted to strings to be used by print | Example : variable = 42
STRING - they are a 'string' of characters . This data type is used to write any word or sentence
| Example : variable = "word"
FLOAT - they are like integers but they always have a dot and they are used to express numbers more accurately than INT | Example : variable = 42.23
Boolean - they can have only 2 values True or False | Example : part_4_of_tutorial = True And you will probably use these when you make state of a thing like a door [it can be either opened either closed]
Rules of Defining a Variable with a Specific Data Type [Recap]
If you need to define a string use double quotes/single quotes . If you need to define an int , don't use double quotes and use just the numbers themselves . If you need to define a float , just make an int with a dot in it and at least 1 number after that . If you need to define a boolean , you need to give it the value True/False and without single/double quotes

Operators
What are they used for?
Operators are obviously used to calculate stuff. It might not be useful when the input is always the same and predefined but its really useful when the input is always different.
A list of operators
Here's a list of the existing operators and what they do:

Of course those 4 operators aren't all , you can also use exponent if you use ** . Here's some examples:

There's also another operator and that's the equal operator = . We are already using it when we define variables and we use it the following way : <variable> = <value/variable> . The thing on the left will get the value from the thing on the right.
Another type of operators
We are now gonna talk about the comparison operators and they are the following :

These operators are really useful when making loops , but we haven't got that far . Still , there's a thing you should know about how they work :
If you do print(3>4) , what do you think it will happen? I advice you do it yourself so I don't destroy the surprise . Done? Alright so as you can see the output is False , because usually 3>4 , actually 3 is never bigger than 4. This works the same to the other ones.
I hear you ask [ why theres equal operator here too, didn't we cover it already? ] Well it's not the same equal operator , this one is translated like this "Is this number from the left the equivalent of the number on the right?" and it outputs a True/False based on what are you trying to compare.
Practice MAKES Perfect!
Your homework is of course 1. try to multiply , divide , add and subtract strings. | and 2. try to add a float with an int and see what happens , also try to make a variable that is made out of addition , subtraction , multiplaction, exponent and division at the same time and try to see whats the order of operators executing .
Keep up the good work , after we finish all the basic python lessons , I'll maybe make lessons about Machine Learning.
Last updated
Was this helpful?