DEV Community

Cover image for Python Data Type
Sajjad Rahman
Sajjad Rahman

Posted on

Python Data Type

In Python, data types determine the type of data that a variable can hold. Different data types have different purposes. Here I am going to write some types of data type

Integer (int)

Integers are whole numbers without decimal points. Examples:

age = 25
height = 175
students_count = 1000
Enter fullscreen mode Exit fullscreen mode

Floating-Point (float)

Floating-point numbers are numbers with decimal points. Examples:

pi = 3.14159
temperature = 25.5
weight = 68.75
Enter fullscreen mode Exit fullscreen mode

String (str)

Strings are sequences of characters enclosed in single (' ') or double (" ") quotes. Examples:


name = "John Doe"
address = '123 Main Street'
message = "Hello, how are you?"
Enter fullscreen mode Exit fullscreen mode

Boolean (bool)

Booleans represent truth values. It can be either True or False. Examples:

is_raining = True
is_sunny = False
is_student = True

List

numbers = [1, 2, 3, 4, 5]
names = ['Alice', 'Bob', 'Charlie']
mixed_list = [10, 'apple', True, 3.14]
Enter fullscreen mode Exit fullscreen mode

Tuple

Tuples are similar to lists, but they are immutable once created. Examples


axiz = (10, 20)
marks = (55, 78, 90)
Enter fullscreen mode Exit fullscreen mode

Dictionary

Dictionaries store key-value pairs and allow accessing values using their keys. Dictionaries are mutable. Examples:

person = {"name": "John", "age": 30, "city": "New York"}
grades = {"math": 90, "science": 85, "history": 78}
Enter fullscreen mode Exit fullscreen mode

Set

Sets are unordered collections of unique elements ( no duplicate) Examples:

fruits = {'apple', 'banana', 'orange'}
prime_numbers = {2, 3, 5, 7, 11}
Enter fullscreen mode Exit fullscreen mode

NoneType (None)

None is a special data type representing the absence of a value. Example:

 result = None
Enter fullscreen mode Exit fullscreen mode

These are some of the essential data types in Python. Understanding data types is crucial for effectively manipulating and processing data in your Python programs.

Remember that Python is a dynamically-typed language, meaning you do not need to specify the data type explicitly when declaring a variable; Python will infer it based on the assigned value.

Top comments (0)