HTML CSS JAVASCRIPT PYTHON JAVA

Python Data Types

Data types in Python define the type of value a variable can store. Python automatically detects the data type based on the value assigned to a variable.

Built-in Data Types

Python has several built-in data types. The most commonly used ones are:

String

A string is used to store text. Strings are written inside single or double quotes.

Example
name = "Ali"
print(name)
Try this code

Integer

Integers are whole numbers without decimal points.

Example
age = 25
print(age)
Try this code

Float

Floats are numbers with decimal points.

Example
price = 10.5
print(price)
Try this code

Boolean

Boolean data types have only two values: True or False.

Example
is_active = True
print(is_active)
Try this code

List

A list is a collection of items. Lists are ordered and changeable.

Example
fruits = ["apple", "banana", "mango"]
print(fruits)
Try this code

Tuple

A tuple is similar to a list, but it is not changeable (immutable).

Example
colors = ("red", "green", "blue")
print(colors)
Try this code

Dictionary

A dictionary stores data in key-value pairs.

Example
person = {"name": "Ali", "age": 25}
print(person)
Try this code

The type() Function

The type() function is used to check the data type of a variable.

Example
x = 10
print(type(x))
Try this code

Why Data Types are Important