Dev.to WebDev 🛠 Dev 👁 0 📖 1 min read

Data types in Python

Numeric Data Types in Python Integer (int) Integers are whole numbers with no decimal point, positive, negative, or zero. students_in_class = 45 Float (float) Floats are numbers with a decimal point. pi = 3.14159 Co

Numeric Data Types in Python

Integer (int)
Integers are whole numbers with no decimal point, positive, negative, or zero.
students_in_class = 45

Float (float)
Floats are numbers with a decimal point.
pi = 3.14159

Complex (complex)
Complex numbers have a real and an imaginary part, written using j for the imaginary unit.

z = 3 + 5j

String Data Type (str)

Strings store text of any length: names, messages, file paths, user input, and configuration values. In Python, strings are immutable sequences of Unicode characters.

name = "Mark Tony"

city = 'Chennai'

Boolean Data Type (bool)
A Boolean holds exactly one of two values: True or False. Booleans power every conditional decision in Python.

is_enrolled = True

has_paid_fees = False

age = 20

print(age >= 18) # True

print(age == 25) # False

print(age != 25) # True

NoneType (None)

None is Python's way of representing "no value" or "not applicable." It has its own type, NoneType, and is not equivalent to 0, False, or an empty string.
if result is None:

print("No result found")

List (list)

A list is an ordered, mutable collection that can hold values of any type, including mixed types.

subjects = ["Python", "Data Science", "Machine Learning"]

scores = [85, 92, 78, 95]

mixed = ["Arjun", 21, True, 9.5]

Tuple (tuple)
A tuple is an ordered, immutable collection. Once created, you cannot change, add, or remove items.

coordinates = (28.61, 77.21)

birthday = (15, "August", 2001)

rgb_color = (255, 128, 0)

Set (set)
A set stores unique values with no guaranteed order. Duplicate values are automatically removed.

enrolled_students = {"Amit", "Priya", "Rahul", "Priya"}

print(enrolled_students) # {'Amit', 'Priya', 'Rahul'} (duplicate removed)

frozenset is the immutable version: once created, you cannot add or remove items.

Dictionary (dict)
A dictionary stores key-value pairs. Keys must be unique and immutable (strings, numbers, or tuples). Values can be any type.

student = {

"name": "Vikram",

"age": 20,

"city": "Bengaluru",

"enrolled": True

}

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.