DATA TYPES

In Python, the data type of immediate values is inferred automatically, meaning the interpreter determines the type of each literal based on how it is written. When you write a value such as 42, 3.14, or "text", Python instantly recognizes them as an integer, floating-point number, or string without requiring any explicit type declaration. This behavior is part of Python’s dynamic typing system, which simplifies coding by allowing developers to focus on the logic of their programs rather than manual type specification.

NUMERIC

These hold integers and decimal values

age = 25
temperature = 98.6

STRINGS

These stores a sequence of characters enclosed in single or double quotes

name = "John Doe"
message = 'Hello, world!'

BOOLEAN

These only hold the values true and false

isTrue = True
isFalse = False

LISTS

These stores collection of items, which can be of different types. Lists in Python are flexible, ordered collections that allow you to store and manage multiple items within a single variable. They are mutable, meaning their contents can be changed after creation by adding, removing, or modifying elements. Lists can hold values of any data type—even mixing types—and support powerful operations such as slicing, appending, sorting, and iterating. Created using square brackets, lists are one of Python’s most commonly used data structures because they provide a simple and efficient way to organize and manipulate dynamic sets of data.

numbers = [1, 2, 3, 4, 5]
fruits = ['apple', 'banana', 'orange']

TUPLES

Tuples in Python are ordered, immutable collections used to store multiple items in a single variable. They allow you to group related data together and access elements by index just like lists, but unlike lists, their contents cannot be changed after creation. This immutability makes tuples useful for fixed data sets, dictionary keys, and situations where data integrity must be preserved. Tuples can contain elements of any type, including other tuples, and are created using parentheses or simply by separating values with commas. Their efficiency and predictability make them a common choice for structured, read-only data in Python programs.

coordinates = (10, 20)

DICTIONARY

Python’s dictionary is a versatile, unordered collection that stores data as key–value pairs, allowing for fast and efficient lookups. Each key in a dictionary must be unique and immutable, while the associated values can be of any type and can be updated at any time. Dictionaries are created using curly braces and are ideal for representing structured data, configurations, and mappings where quick access to values by name or identifier is important. Their flexibility, dynamic nature, and constant-time average lookup performance make dictionaries one of Python’s most powerful and widely used data structures.

person = {'name': 'Alice', 'age': 30}

SET

A set in Python is an unordered collection of unique elements designed primarily for fast membership testing and eliminating duplicates. Sets are mutable, meaning you can add or remove items, but they do not preserve order and cannot contain unhashable types like lists or other mutable objects. Created using curly braces or the set() constructor, sets support powerful mathematical operations such as union, intersection, and difference, making them useful for comparing datasets or filtering out repeated values. Their efficiency and automatic handling of uniqueness make sets a practical choice for tasks involving distinct elements and quick lookups.

uniqueNumbers = {1, 2, 3}

NONE

In Python, None is a special singleton object used to represent the absence of a value or a null result. It is of type NoneType, and there is only one instance of it throughout an entire program, making it a reliable placeholder when no meaningful data is available. Developers commonly use None to indicate optional function parameters, default return values for functions that do not explicitly return anything, or uninitialized variables such as emptyValue = None. Because None evaluates to False in boolean contexts, it also plays an important role in control flow decisions. Overall, None provides a clear and consistent way to express “nothing here” within Python code.

emptyValue = None

Last updated