[001]Introduction to the Python Basics: Int and Float

Koay Yong Cett
6 min readJun 16, 2020

In order for any programmer to learn a language. There are four main points/ key things that we really need to master for any sort of language including python.

Photo by Siora Photography on Unsplash

1.The TERMS of programming languages

  • Sometimes a programming languages has different words and definitions for these words which we need to memorize it such as the statements, variables and instantiation etc.
  • This might be complicated sounded words but you need to understand what they mean. Then only you are able to talk to other programmers.

2.The languages DATA TYPES

  • We also need to learn about a language data type that is what sort of data can a program hold on to. You probably can think of it as a value just like in the real life.
  • We have different ways to represent values like number, letters and symbols. In programming, we have all theses data types to store information and each programming language has different data types.

3.The ACTIONS

  • Next, we need to learn about actions. All programming requires us to tell our machine how to store data/retrieve data and perform some action on it.
  • We are just utilizing the memory and performing some actions. It is really important to learn all this actions in a programming that you want to excel on it.

4.The BEST PRACTICES

  • We are going to learn the best practices of each language. There is good ways of writing the Python code as well as the bad ways of writing the code.
  • When we build our applications and our programs, we don’t want something that is not reliable and not easy manageable. We want a solid structure and foundation of programs and applications.

Let’s dive into the DATA TYPES in Python :

(Learn all the options of data types that we have in Python.)

  • What are these? Data types is a value in python so you can think of it exactly as the values. For instance, int would be used to represent all numbers and str will represents all letters in a program. A program is just simply an instructions that tell a computer what to do and what it actually means.
  • It’s all about storing the information a data type and modifying that information. Thus, we are taking actions using these data types.

Two crucial steps when learning a programming language :

  1. We have these data types that we need to understand that exist in the language
  2. Then, we need to learn how to manipulate the data by create, store, read, change, remove this data from the machine.

Other Data Types?

  • The fundamental data types is the core to the python language.
  • We also have something called classes. These classes will be the custom types. Therefore, I am able to create a class based on the name I prefer.
  • Then, we also have the specialized data types. These data types are not built into Python but they are special packages and modules which we can use from the libraries. Think of it as extensions that we can add to the language.
  • Another type of data that is called None. As the name suggests, it means nothing. It’s something like the idea of zero in math and the absence of value. Basically, it’s nothing.

Int and Float Data Types:

👉Float stands for a floating point.

👉Int stands for integer.

  • An integer is a number such as 3 , 4 and 5. These are all integers in programming language.
  • We can use integers to do mathematical operations.
  • For instance, 2+4 and we run it. Nothing is printed as we have to perform some action on these data types to yield the result.
  • Various mathematical operations can be performed here and it’s working.

Here, start the interesting parts:

Until now, we have used what we call integers and all these are a whole numbers. There is no decimal places and just normal integers.

A neat trick here:

  • We can use the type to check the type for (2+4). This is another action called type that we can perform to know what the data types in the bracket.
  • We have 3 int class and 1 float class. (2+4)=6 (int), (2–4)=-2 (int), (2*4)=8 (int) and (2/4)= 0.5 (float)
  • 0.5 is a float and it is referred as a floating point number which is simply a number with decimal point.
  • We still get a float with 0.00001 as it have decimal points.
  • We also get a int for 0 as zero has no decimal points.

Why do we have to make this distinction in programming specifically in Python?

👉Well a float takes up a lot more space in memory than an integer.

  • The machine don’t really understand what are we writing. They only understands zeros and ones and store this numbers in binary numbers which is zeros and ones.
  • The problem is when the numbers have decimal points. For example, the number 10.9 and it is hard to represent in the binary numbers format due to the decimal points.
  • Thus, the floating point number essentially stores these numbers in two different location. One location for the 10 and another location for the 9.

⭐️(We no need to get technical here but that is the idea where we need more memory to store the number that have decimal points)

Both int and float are used for the numbers right?

  • Python is going to automatically format the type to whatever that will make sense.
  • When we add an integer number (20) and a floating number (1.1), the Python automatically converted to a floating point.
  • When we add both floating number (1.1 and 9.9) which will be equal to 11 that is an integer. However, the result still is a floating number. Why?
  • When we remove the type action and the result yielded is 11.0 which have a decimal point. It keeps the floating point number.

Some other mathematical operation:

  • (2 ** 3) means that 2 to the power of 3(2³).
  • (5//4) which return an rounded down integer(1.25=1).
  • (5%4) means that 5 modulo 4 yielded 1 which the remainder.

We have also math functions:

  • Math functions is a type of function specific for math such as round and abs functions. The round() allows us to round the number whereas the abs() means that no negative number will be yielded.

We can google it and there are a lot can be used:

source: https://www.programiz.com/python-programming/modules/math

More information can be found here:

Thanks for reading my stories 😄

--

--

Koay Yong Cett

A Bachelor CS student with major in Network Security (UniSZa). Every stories I shared is based on my personal opinion. Thanks you. Having my Internship now.