#3 Numbers in Python — Python For Beginners
The first primitive datatype we will learn
Hello Coding Friends! Today we are going to learn something about the primitive datatype numbers. We will also learn about the operations and methods you can use for them. I will explain everything. So open your IDE and let’s start coding!
What are primitive datatypes?
Primitive datatypes are datatypes which build the basics of datatypes. Other datatypes are based on them. One primitive datatype are numbers and we are talking about these in this article.
What are numbers in Python?
To be honest, numbers in Python are not really complicated. They are almost like numbers in the real world. A 6 in Python is equal to a 6 in the real world.
Different number types:
Something to keep in mind about numbers in Python is that there are more than one kind of number. The two you will use the most often are integers (int) and floats (float). Integer means a full number like 1,2,3,4,5,6,7, …. And float means numbers like 1.5, 3.9, 5.7, …. There is also a number type called long, which is kind of an integer but it has “unlimited” precision (sure, the available adress space is the limit). If you want to know it: The limit of an integer is 2147483647. As this is still a high number you can imagine that you won’t have to use longs that often. So let us stick with integer (we will do so in this Python For Beginners Series).
Operations for numbers (Operators):
You know the different operators for numbers in the real world (like normal math), don’t you? Python is following the real math operators as well (well, sounds logical). In the following a short definition of all the different operators:
- ** = Exponent ( 2 ** 3 = 8)
- % = Modulo (22 % 8 = 6)
- // = Integer Division (22 // 8 = 2)
- / = Division (6 / 2 = 3)
- * = Multiplication (4 * 5 = 20)
- - = Subtraction (5–2=3)
- + = Addition (8 + 2 = 10)
I also listed them after their highest rank, so which operator will be used first. Like 6 + 4 * 3 = 18 (4 * 3 = 12 + 6 = 18).
Get l0ckD2wN’s stories in your inbox
Join Medium for free to get updates from this writer.
I hope it is understandable. There are some other things to numbers, like casting integers, floats, …, but in my opinion you don’t need them as a beginner. That is why I won’t cover them in this article. If we will need any of these things, which I don’t explain here, I will show you then how they work.
Now it’s your turn!
Go to your IDE and practice the things we learned here. If you don’t know how to install an IDE watch my #1.2 Installing a Code Editor (IDE) — Python for Beginners article! Just try a few operations or methods we learned here. Practice, practice, practice. Repeat, repeat, repeat. You will learn the better the more you repeat the right things.
You learned a lot of new things today, even though most things like float numbers and operators were not that new to you due to school education and daily usage. You see learning coding is not that hard as it first might look. I will continue breaking down the big things into small things so everyone will be able to follow.
As always, if you have questions leave them in the comments below. Have a great day and I see you in the next one!
Until then!
l0ckD2wN











