Integers and Float in Python3

Let’s move on to variable types. Python has several built-in data types. Data types can be classified as numeric, sequences, mapping, files, classes, instances and exceptions. You’ll be introduced to all of these as this tutorial progresses but now, we’ll look at numeric data types and sequence type. String being a sequence type which we’ve looked at before.

Integers

So, start with the basic data type, its integer. An integer being a whole number, a number that hasn’t got any decimal points.



 So, an integer is just a whole number. It’s a number having no fractional part, where as a float is another name for a real number. That is a number having a fractional part after the decimal point. There is a very small number of computer languages that make no distinction between real numbers and integers. In the computers, computations using integers these whole numbers, are significantly faster than using floating point numbers. That’s the reason we are distinguishing between an integers as a whole number and a real number, a floating point number and that’s because it’s a lot faster to process.

Floating Point

Now, floating point numbers on the other side, they are used to represent numbers having a fractional part. So the maximum float value on a 64 bit computer, it’s quite large. Basically a number that actually moves the decimal point 308 places to the right and the smallest float is a negative number which has 307 zeros before the decimal point. So it’s obviously a huge variance and a huge number can be stored in that floating point number. Floating points have 52 digits of precision, which could be adequate for most purposes from financial calculations where   you’re needing decimals, and because python doesn’t really have variable declarations, that’s where you specify the type of a variable before you can use it.
So, let’s see some examples.




Now, as you can see there is, a divided by b, the actual answer is returned as a float with a decimal point, and that’s the thing we have to keep in mind with a divide and a division operation, in python by default it returns as a float. If you want the result to return as an integer, a whole number, you need to use the two slashes.

Comments

Popular posts from this blog

String Slicing and Picking sub-string in Python3

Variable in Python3