Data Types

Compound Data Types

Explore the core Python compound data types such as lists, tuples, dictionaries, and sets. Learn their characteristics, how they handle different data types, and discover practical examples to build your foundational programming skills.

Compound data types

Compound data types are data types that can hold different types of values together. They are basically composed of other data types, such as lists, for instance.

Lists

Lists (list): Ordered and mutable collections of items. The elements inside can be of different data types.

topics_covered = ["Variables", "Loops", "Functions", "Data Structures"] print("Topics covered:", topics_covered)

List data type in Python

Let’s define another list with various data types stored in it.

different_types_list = [False, 100.5, "Hello!"] print("A list containing various types: ", different_types_list)

List data type in Python

Tuples

Tuples (tuple): Ordered and immutable collections of items. The elements inside can be of different data types.

days_of_the_week = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday") print("Days of the week:", days_of_the_week)

Tuple data type in Python

Let’s define another tuple with various data types stored in it.

different_types_tuple = ("Strings", 20, 15.5, True, None) print("A tuple containing various types: ", different_types_tuple)

Tuple data type in Python

Dictionaries

Dictionaries (dict): Unordered collections where each item is represented as a key-value pair. All keys are unique.

instructors_courses = {"Ash": "Python Basics", "X12": "Advanced Python", "Is": "Data Science / ML with Python"} print("Instructors and Courses:", instructors_courses)

Dictionary data type in Python

Sets

Sets (set): Unordered collections of unique elements.

set_variable = {1, 2, 3, "How many data types are there?"} print("Our Set:", set_variable)

Set data type in Python

On this page

    In This Module

    2. Data Types