Compound Data Types

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)

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)

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)

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)

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)

Sets

Sets (set): Unordered collections of unique elements.

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