Table of Contents
In this tutorial, we will discuss the Python language Numbers datatype.
In every programming languages, they have many data types. In Python, data types are used to classify every particular type of data. The number is one of the data types used to store numeric values in Python.
Python supports four different numerical types
Integer, long integer, floating-point and complex numbers are under the category number data type in python
Eg – 5 – it is an integer, it has no decimal point
5.o – it is an float number, it has decimal point
| Number System | Prefix |
|---|---|
| Binary | 0b or 0B |
| Octal | 0o or 0O |
| Hexadecimal | 0x or 0X |
print(0b10011010); #The output given The decimal value of binary number 10011010: print(0xFD); #The output given The decimal value of Hexadecimal number FD: print(0o16); #The output given The decimal value of octal number:
When the above code is executed, The following output is displayed
154 253 14
Calculate sum of python numbers
print(0b1101+0b1011) #Find addition of two binary numbers print(0xFB+0xA) #Find addition of two hexadecimal numbers print(0o5+0o4) #Find addition of two Octal numbers
When the above code is executed, The following output is displayed
24
261
9
In python language, we can convert the type of number into another
We can use to convert some of built-in(predefined) function to type conversion of number data type such as int(), float(), complex()
Related Post
Multiply two numbers in Java using scanner| 5 different ways In this article, we will…
5 Different ways to Divide two numbers in Java using scanner In this article, we…
Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…
10 ways to subtract two numbers in Java In this article, we will discuss the…
Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…
How to Divide two numbers in Java| 5 different ways In this article, we will…
This website uses cookies.