Variables: Dictionaries

Attention: Our videos have subtitles in all partner languages. You can switch on subtitles in the youtube player by clicking the gear wheel and selecting your preferred language.

In this section we introduce the variable type “dictionary” and show how it can be used. It's time for Big Data. Our complex reality requires processing increasing amounts of information, and that power is available in Python through the Dictionaries. They facilitate the management of complex systems, by connecting a key to a value, allowing a very efficient and fast system to store and retrieve data in our code.

Function to calculate the square of a number
1) Define a function called calculate_square that takes one argument, number, and returns the square of that number. 2) Use this function to calculate and print the square of a given number (e.g., 5).
Solution
 # Define a function to calculate the square
def calculate_square(number):
    return number ** 2

# Calculate and print the square of a number
result = calculate_square(5)
print("Square:", result)