what are Data types in python

Опубликовано: 09 Июль 2026
на канале: Images learning
0

What are Data Types in Python?

A data type defines the kind of value stored in a variable. It tells Python what type of data the variable contains so that Python can store it correctly, perform valid operations, and produce the expected result. Every value in Python belongs to a specific data type, and Python automatically identifies the data type when a value is assigned to a variable.

Different kinds of data are used for different purposes. Numbers are used for mathematical calculations, text is used to store names and messages, Boolean values are used to represent True or False conditions, and collections are used to store multiple values together. Choosing the correct data type makes the program easier to understand, maintain, and execute correctly.

age = 25
price = 99.99
name = "Vikram"
is_student = True

In the above example, age is an integer, price is a floating-point number, name is a string, and is_student is a Boolean value. Python automatically detects these data types without requiring the programmer to declare them.

Python provides several built-in data types. The most commonly used data types are int, float, str, bool, list, tuple, set, and dict.

An Integer (int) stores whole numbers without a decimal point.

count = 100

A Float (float) stores numbers that contain a decimal point.

temperature = 36.5

A String (str) stores text or a sequence of characters enclosed in quotation marks.

city = "Hyderabad"

A Boolean (bool) stores only two values: True or False. It is mainly used in conditions and decision-making.

is_logged_in = True

A List stores an ordered collection of items. Lists are mutable, which means their values can be changed after creation.

marks = [80, 85, 90]

A Tuple also stores an ordered collection of items, but tuples are immutable, which means their values cannot be modified after they are created.

coordinates = (10, 20)

A Set stores unique values. Duplicate values are automatically removed.

colors = {"Red", "Green", "Blue"}

A Dictionary (dict) stores data as key-value pairs, allowing values to be accessed using their corresponding keys.

student = {
"name": "Vikram",
"age": 25
}

Python provides the type() function to identify the data type of any variable or value.

name = "Vikram"
print(type(name))

Output

str

One of Python's most useful features is Dynamic Typing. A variable is not permanently associated with one data type. The same variable can store different types of values at different times, and Python automatically determines the correct data type during execution.

x = 10
x = "Hello"
x = 12.5

In this example, x first stores an integer, then a string, and finally a floating-point number. Python accepts all these assignments because it automatically identifies the current data type.

Using the wrong data type may cause errors during program execution. For example, Python cannot directly add a string and an integer.

x = "10"
y = 5

print(x + y)

This code produces an error because one value is text and the other is a number.

Python provides type conversion (also called type casting) functions to convert one data type into another whenever required.

x = "100"
number = int(x)

print(number)

After conversion, the string value "100" becomes the integer 100, allowing it to be used in mathematical operations.

Understanding data types is essential because every variable stores a value, and every value belongs to a particular data type. Selecting the correct data type helps write accurate, readable, efficient, and maintainable Python programs.


На этой странице сайта вы можете посмотреть видео онлайн what are Data types in python длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Images learning 09 Июль 2026, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели раз и оно понравилось 0 зрителям. Приятного просмотра!