Python Numeric Datatypes

There are three Python Numeric Datatypes int, float, complex, and in mathematics, these are represented as integers, decimals, and complex numbers.

Example

x = 12
y = 12.3
z = 12j  # we use "j" to represant complex numbers
print(type(x))
print(type(y))
print(type(z))

Output

<class 'int'>
<class 'float'>
<class 'complex'>

Int

In Python int, or integer is a whole number(positive, negative, and zero) and the length is unlimited.

Example

x = 1227348742474
y = -12234353546
z = 0
print(type(x))
print(type(y))
print(type(z))

Output

<class 'int'>
<class 'int'>
<class 'int'>

Float

In Python “Float or “floating-point numbers” are similar to decimal numbers in maths.

Example

x = 122734.8742474
y = -12234.353546
z = 0.2032
print(type(x))
print(type(y))
print(type(z))

Output

<class 'float'>
<class 'float'>
<class 'float'>

Complex

In Python, “complex numbersare created using “j” after a number.

Example

x = 12 + 3j
y = -12 - 0.4j
z = 4j
print(type(x))
print(type(y))
print(type(z))

Output

<class 'complex'>
<class 'complex'>
<class 'complex'>

Also Read:

Top 25 Pattern Programs in C++

In this article, I will show you the Top 25 Pattern Programs in C++ that you must learn which will help you to understand the usage of nested loops. We will learn to create different geometrical shapes like Squares, triangles, Rhombus, etc. We have provided the code as well as output for all the patterns…

Continue Reading Top 25 Pattern Programs in C++

Currency Converter in C++

In this article, we will build a simple program for Currency Converter in C++. The user will be able to convert currencies like Dollar, Euro, Pound, and Rupee. This is a console application and very simple to understand as we only use a bunch of conditionals to write the entire program. Features Users can convert…

Continue Reading Currency Converter in C++

SQLite | CRUD Operations in Python

CRUD stands for Create Read Update Delete. I will show you how to perform CRUD Operations in Python. You need basic Tkinter and SQLite knowledge before you read further. This app is straightforward, when you will open this app, a GUI with 4 green colored buttons will open to perform CRUD(create read update delete) operations.…

Continue Reading SQLite | CRUD Operations in Python

Number Guessing Game in C++

In this article, we will build a simple Number Guessing Game in C++. It’s a game in which the player has to guess a secret number in a range that is generated by the computer and upon a wrong guess by the player, the game will give hints to the player to guess the correct…

Continue Reading Number Guessing Game in C++

C++ Project Structure

Hello everyone, have you ever wondered while looking inside a big C++ project structure what are these different folders, subfolders, and files used for? Especially when we have just started working with C++ we get lots of questions and confusion regarding this. So let’s talk about the C++ Project Structure of a general application.  Whenever…

Continue Reading C++ Project Structure