A data type defines the kind of value a variable contains. In programming, data types are essential because they help to determine the operations that can be performed on the data. Some commonly used Python data types are: integers, floating-point numbers, strings, lists, tuples, and dictionaries. Understanding these types can greatly enhance your coding capabilities and allow for more efficient data manipulation.

Data Type

Example

Used For

int

25

Whole numbers

float

25.5

Decimal numbers

complex

2 + 3j

Complex numbers

str

"Hello"

Text

bool

True

True/False values

list

[10, 20, 30]

Ordered collection

tuple

(10, 20, 30)

Ordered, fixed collection

set

{10, 20, 30}

Unique values

dict

{"name": "Amit"}

Key-value data

None

None

No value

Data Types in Python

An integer is a whole number without a decimal point. It can be positive, negative, or zero and does not include any fractions or decimals. Integers are often used in various mathematical contexts and can be represented on a number line, extending infinitely in both directions.

Input

Explanation

age = 25

print(age)

print(type(age))

Output

25 is a whole number, which means that it belongs to the set of integers. Thus, Python identifies it as an int, allowing developers to use it in calculations and various functions where whole numbers are needed.

25

<class 'int'>

1. Integer (int)

A float is a number that contains a decimal point, and it is commonly used in programming and mathematics to represent fractions or precise values. For instance, in programming languages, a float can be critical in scenarios involving calculations that require a high degree of accuracy. They allow for greater flexibility and enable a wider range of numerical exercises, thus playing an essential role in various computations.

Input

Explanation

price = 99.50

print(price)

print(type(price))

Output

price = 99.50 creates a variable named price and stores the decimal value 99.50 in it. Since the value contains a decimal point, Python treats it as a float (floating-point number).

print(price) displays the value stored in the price variable.

print(type(price)) checks the data type of the variable. Python returns <class 'float'>, confirming that price is a floating-point number.

99.5

<class 'float'>

2. Floating-Point Number (float)

Python also supports complex numbers. A complex number contains a real part and an imaginary part, allowing for operations and computations that involve both dimensions. This makes it a versatile option for mathematical modeling and simulations, especially when dealing with phenomena that require both real and imaginary components.

Input

Explanation

number = 3 + 4j

print(number)

print(type(number))

Output

number = 3 + 4j creates a variable named number and stores a complex number in it. Here, 3 is the real part and 4j is the imaginary part. In Python, j represents the imaginary unit.

print(number) displays the complex number as (3+4j).

print(type(number)) checks the data type of the variable. Python returns <class 'complex'>, confirming that number is a complex data type.

(3+4j)

<class 'complex'>

3. Complex Numbers (complex)

In Python, a string (str) is a sequence of characters used to store text. Strings can be written inside single quotes (' ') or double quotes (" "). They can contain letters, numbers, spaces, and special characters. Strings are commonly used to store names, messages, and other text-based information.

Input

Explanation

first_name = "Rahul"

last_name = "Sharma"

full_name = first_name + " " + last_name

print(full_name)

print(type(full_name))

Output

first_name = "Rahul" stores the first name in the first_name variable, while last_name = "Sharma" stores the last name in the last_name variable.

full_name = first_name + " " + last_name combines both strings using the + operator. The " " adds a space between the first and last name.

print(full_name) displays the complete name as Rahul Sharma.

print(type(full_name)) checks the data type of full_name. Since it contains text, Python returns <class 'str'>, which means it is a string.

Rahul Sharma

<class 'str'>

4.String (str)

A Boolean value represents one of two conditions:

  • True

  • False

Input

Explanation

is_student = True

has_passed = False

print(is_student)

print(has_passed)

Output

Boolean values are commonly used when working with conditions and decision-making in Python.

is_student = True creates a variable named is_student and assigns it the Boolean value True. Similarly, has_passed = False creates a variable named has_passed and assigns it the Boolean value False.

print(is_student) displays True, while print(has_passed) displays False. In Python, Boolean values represent one of two possible states: True or False. They are commonly used in conditions and decision-making.

True

False

5. Boolean (bool)

A list is used to store multiple values in a single variable.

Lists are written using square brackets [].

Input

Explanation

Output

fruits stores multiple values in a list, written using [].

A list can contain different data types, such as strings, integers, and floats. print() displays all the values stored in the list.

['Apple', 'Mango', 'Banana']

6. List (list)

fruits = ["Apple", "Mango", "Banana"]

print(fruits)

A list can contain different types of values:

student = ["Amit", 20, 85.5]

print(student)

['Amit', 20, 85.5]

A tuple is similar to a list, but its values cannot normally be changed after creation.

Tuples use parentheses ().

Input

Explanation

Output

colors = ("Red", "Green", "Blue") creates a tuple containing multiple values. Tuples are written using parentheses () and their values cannot normally be changed after creation.

print(colors) displays the values, while print(type(colors)) confirms that colors is a tuple.

('Red', 'Green', 'Blue')

<class 'tuple'>

7. Tuple (tuple)

colors = ("Red", "Green", "Blue")

print(colors)

print(type(colors))

A set is a collection of unique values that are important in various branches of mathematics. Sets use curly brackets {} to denote the elements contained within. For example, a set can represent numbers, characters, or even objects. It is essential to understand the concept of sets, as they provide a foundation for more complex mathematical theories and applications.

Input

Explanation

Output

numbers = {10, 20, 30, 10} creates a set containing multiple values. Sets store only unique values, so the duplicate 10 is automatically removed.

print(numbers) displays the unique values as {10, 20, 30}.

{10, 20, 30}

8. Set (set)

numbers = {10, 20, 30, 10}

print(numbers)

A dictionary stores information in key-value pairs.

These pairs consist of unique keys that map to corresponding values, allowing for efficient data retrieval and organization.

Input

Explanation

Output

student is a dictionary that stores data in key-value pairs. Here, "name" and "age" are keys, while "Amit" and 20 are their values.

print(student) displays the complete dictionary. student["name"] accesses the value stored under the "name" key, so the output is Amit.

Amit

9. Dictionary (dict)

student = { "name": "Amit", "age": 20 } print(student)

You can access a value using its key:

print(student["name"])

{'name': 'Amit', 'age': 20}

None represents the absence of a value.

Input

Explanation

Output

It is quite useful when a variable currently has no meaningful value, as it can help in understanding the absence of data and allows for more effective handling of situations where a value is not yet established or available.

None

<class 'NoneType'>

10. None (NoneType)

result = None

print(result)

print(type(result))

Contact

Reach out for AI courses and support

Email

Phone

careers@ahkacademy.in

Mo:- +91-7769920076

}

© 2025. All rights reserved.