Getting Started

Python - IntroductionPython - Hello World ProgramPython - SyntaxPython - Data TypesPython - Variables

Operators

Python - Arithmetic OperatorsPython - Relational OperatorsPython - Logical OperatorsPython - Assignment OperatorsPython - Bitwise OperatorsPython - Membership OperatorsPython - Identity OperatorsPython - Increment and Decrement Operators

Conditions

Python - If Else statement

Loop

Python - While LoopPython - For Loop

Numbers

Python - NumbersPython - Number Conversion

Strings

Python - StringsPython - String OperatorsPython - String FormattingPython - String MethodsPython - String Format Method

List

Python - ListPython - List Methods

Tuple

Python - Tuple

Set

Python - SetPython - Set Methods

Dictionary

Python - DictionaryPython - Dictionary Methods

Functions

Python - FunctionsPython - Functions - Variable length argumentsPython - Lambda Function

Scope of Variables

Python - Scope of Variables

Modules

Python - ModulesPython - Math ModulePython - JSON ModulePython - datetime ModulePython - time Module

I/O

Python - Read input from keyboard

File

Python - File Handling

Exception Handling

Python - Exception Handling

OOP

Python - Classes and ObjectsPython - Class Constructor __init__ methodPython - Class Destructor __del__ methodPython - Built-in Class AttributesPython - InheritancePython - Method OverridingPython - Method Overloading

Package Management

Python - PIP

Python - MySQL

Python - MySQL - Getting StartedPython - MySQL - Insert dataPython - MySQL - Select dataPython - MySQL - Update dataPython - MySQL - Delete data

Python - CSV

Python - Read data from CSV filePython - Write data in CSV file

Python - Numbers

Python

python logo

In this tutorial we will learn about Numbers in Python.

We use number data type to hold numerical values.

A variable of number type is immutable i.e. when we reassign a new value to the same variable then a new object is created.

Number types

We can group numbers into four types listed below.

Integer Number

These represents positive and negative whole numbers without decimal point.

Example of integer: -100, 10, 0, -1, 1000

Integers are often referred as int and if you come from other programming language like C or Java then you know int data type.

In the following Python code we are creating a variable and assigning an integer value.

# variable
x = 10

# detail
print("Value of x:", x, " Type of x:", type(x))

This will give us the following output.

Value of x: 10  Type of x: <class 'int'>

We use the type() function to find the type of a variable.

Long a.k.a Long Integer

Long represents positive and negative whole numbers without decimal point and can hold larger integer values.

Long values are ended with uppercase L or lowercase l.

Example of long: 123456789012345678901234567890L

You will generally see uppercase L with long integer values as lowercase letter l can be confused with number 1.

Long are also referred as long integer.

long and int were unified in Python. So, now we use int to also hold very large integer values. Check out this documentation.

Floating Point Number

Float or Floating Point numbers represent real numbers with decimal point.

Example of float: -123.456, 0, 678.9

In the following Python code we are creating a variable and assigning a floating point value.

# variable
x = 3.14

# detail
print("Value of x:", x, " Type of x:", type(x))

This will give us the following output.

Value of x: 3.14  Type of x: <class 'float'>

Complex Number

Complex data type is used to represent complex number.

In Python complex numbers are represented as x + yj where, x represent the real part and y represent the imaginary part.

Example of complex numbers: 10+4j, -1+1j

In the following Python code we are creating a variable and assigning a complex value.

# variable
x = 3 + 14j

# detail
print("Value of x:", x, " Type of x:", type(x))

This will give us the following output.

Value of x: (3+14j)  Type of x: <class 'complex'>

The del statement

We use the del statement to delete the reference of a number object.

In the following example we are deleting a single number objects.

del x

We can also delete multiple number objects by separating them with comma.

del x, y, z