The basic types of Python

In this blog, we are going to explore some more about the use of the basic types in Python. Python has a couple of built-in types that you can use while typing your code. I am going to explain a couple of them ordered from the most simple to more difficult.

First integers, integers are just normal whole numbers. In Python is it possible to make them as long as you want (until your own memory on your computer can’t handle it anymore). To print them, you just have to type: print(“integer”). See my example in Thonny.
There are also three kind of preset integers in Python; the binary (b), octal (o) and hexadecimal (x) integers. To make these integers you have to print zero (0), the letter that stands behind the integer name and the value that you want to make of it. So if you want the integer two times each other it is 100 behind the letter. Three times each other is 1000 behind the letter. So for example the binary is print(0b10) gives you 2. Print(0x100) gives you 16*16. In my example I showed a couple:

You can alos make float numbers, those numbers are not whole numbers, but have decimals behind the comma. There are two different ways to work with the difference between integers and float numbers. The first thing that you can do is asking Python with which of two you are working. The output is the type in that case. You can also print the number that you want and yout output will display it. You can also use the scientific notation for it and the output becomes the number as float.
You can also adapt a float to an integer in different ways. You can use the function “round” to round your float: 1.3 becomes 1 and 1.8 becomes 2. Another way is to use “int”, that rounds it to the closest number to zero: so 1.3 and 1.8 becomes 1.

It is also possible to let Python work with complex numbers. They are expressed as: “number +numberj”, so far example 12+8j. You can also ask for what type it is:

While working with Python, you are going to use strings quite often. Strings is very easily just printing text or variables. If you want to print text, you need to put the text between single quotes and single brackets. To print the value of a variable, you only need to put it between single brackets, of course you need to define the variable first. If you want to combine the value of a variable with text, you need to do exact as described here and divide the text and variable with a comma. If you want a quote in the text of your string, you need to use double quotes to begin and end your text. If you want to use double quotes in your text, you need to open and end your string with single quotes. Another way to achieve quotes in your string is to use a slash in front of the quotes.

I explained in this log a couple of the most basic types with Python. If you want more information this site can useful. Hopefully you understand everything you read here!

Plaats een reactie

Vul je gegevens in of klik op een icoon om in te loggen. logo

Je reageert onder je account. Log uit /  Bijwerken )

Google photo

Je reageert onder je Google account. Log uit /  Bijwerken )


Je reageert onder je Twitter account. Log uit /  Bijwerken )

Facebook foto

Je reageert onder je Facebook account. Log uit /  Bijwerken )

Verbinden met %s

Maak je eigen website aan bij
Aan de slag
%d bloggers liken dit: