Back to courses
Digital Skills beginner

Introduction to Python for Data

Duration0 hours
Modules7
Get started — free →

Course outline

Module 1 Module 1: Python Basics and Setup

Python Basics and Setup

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. Which command is used to check the installed Python version from the terminal?
  • A. python --version ✓
  • B. python --start
  • C. python --check
  • D. python --info

Why: The flag --version prints the installed Python interpreter version. The other options are not standard Python command-line flags.

Q2. Which of the following is the correct way to print the text Hello, Data! in Python 3?
  • A. echo 'Hello, Data!'
  • B. print('Hello, Data!') ✓
  • C. console.log('Hello, Data!')
  • D. write('Hello, Data!')

Why: In Python 3, print() is a built-in function that outputs text to the console. echo and console.log belong to other languages, and write() is not a built-in function.

Q3. What is the output of the following code? x = 7 y = 2 print(x // y)
  • A. 3.5
  • B. 3 ✓
  • C. 4
  • D. 2

Why: The // operator performs floor division, which divides and rounds down to the nearest whole number. 7 divided by 2 is 3.5, which floors to 3.

Q4. Which Python package manager is most commonly used to install libraries such as pandas and numpy?
  • A. npm
  • B. pip ✓
  • C. gem
  • D. cargo

Why: pip is Python's standard package installer. npm is for JavaScript, gem for Ruby, and cargo for Rust.

Q5. Which of these is a valid variable name in Python?
  • A. 2nd_value
  • B. data-frame
  • C. _total_rows ✓
  • D. class

Why: Variable names cannot begin with a digit, cannot contain hyphens, and cannot be reserved keywords like class. _total_rows follows all naming rules.

Module 2 Module 2: Working with Variables and Data Types

Working with Variables and Data Types

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. Which of the following is the correct way to create a variable named age that stores the integer 25 in Python?
  • A. age == 25
  • B. age = 25 ✓
  • C. 25 = age
  • D. var age 25

Why: In Python, the single equals sign (=) is the assignment operator that stores a value in a variable. The double equals (==) compares values, and the other options are not valid assignment syntax.

Q2. What data type is the value 3.14 in Python?
  • A. int
  • B. str
  • C. float ✓
  • D. bool

Why: Numbers with a decimal point are floating-point numbers, represented by the float type in Python. int is for whole numbers, str for text, and bool for True/False values.

Q3. What will type('Hello') return in Python?
  • A. <class 'char'>
  • B. <class 'text'>
  • C. <class 'string'>
  • D. <class 'str'> ✓

Why: In Python, text values are of type str (short for string). Calling type() on a string literal returns <class 'str'>.

Q4. Which of the following is a valid variable name in Python?
  • A. 2nd_place
  • B. my-variable
  • C. total_score ✓
  • D. class

Why: Variable names cannot start with a digit, cannot contain hyphens, and cannot be reserved keywords. total_score follows all naming rules, while class is a reserved keyword in Python.

Q5. What is the result of the expression bool(0) in Python?
  • A. True
  • B. None
  • C. 0
  • D. False ✓

Why: In Python, the number 0 is considered falsy when converted to a boolean, so bool(0) evaluates to False. Most other non-zero numbers and non-empty values evaluate to True.

Module 3 Module 3: Control Flow and Functions

Control Flow and Functions

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. What will the following code print? for i in range(3): print(i)
  • A. 1 2 3
  • B. 0 1 2 ✓
  • C. 0 1 2 3
  • D. 1 2

Why: range(3) produces the integers 0, 1, and 2. The loop starts at 0 by default and stops before 3, so it prints 0, 1, and 2 on separate lines.

Q2. Which keyword is used to define a function in Python?
  • A. function
  • B. func
  • C. define
  • D. def ✓

Why: Python uses the keyword 'def' followed by the function name and parentheses to define a function. 'function' and 'func' are not Python keywords.

Q3. What is the output of this code? x = 7 if x > 10: print('big') elif x > 5: print('medium') else: print('small')
  • A. big
  • B. medium ✓
  • C. small
  • D. Nothing is printed

Why: x is 7. The first condition (x > 10) is False, so Python checks the elif condition (x > 5), which is True. It prints 'medium' and skips the else block.

Q4. What does the 'return' statement do inside a function?
  • A. It prints a value to the screen
  • B. It sends a value back to the caller and ends the function ✓
  • C. It restarts the function from the beginning
  • D. It declares a new variable

Why: The return statement passes a value back to whatever called the function and immediately exits the function. Unlike print, it does not display anything by itself.

Q5. Which loop would you use to repeat code as long as a condition remains True?
  • A. for loop
  • B. while loop ✓
  • C. if loop
  • D. def loop

Why: A while loop repeats its block as long as its condition evaluates to True. A for loop is typically used to iterate over a sequence, and 'if' and 'def' are not loop constructs.

Module 4 Module 4: Data Structures: Lists, Dicts, and Tuples

Data Structures: Lists, Dicts, and Tuples

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. Which data structure in Python is ordered and mutable?
  • A. Tuple
  • B. List ✓
  • C. Set
  • D. String

Why: Lists are ordered collections whose elements can be changed, added, or removed after creation. Tuples are ordered but immutable, sets are unordered, and strings are immutable.

Q2. What will `len(my_dict)` return if `my_dict = {'a': 1, 'b': 2, 'c': 3}`?
  • A. 6
  • B. 2
  • C. 3 ✓
  • D. 1

Why: The len() function on a dictionary returns the number of key-value pairs, which is 3 here. It does not count the individual keys and values separately.

Q3. How do you access the first element of a list called `scores`?
  • A. scores[1]
  • B. scores(0)
  • C. scores[0] ✓
  • D. scores.first()

Why: Python uses zero-based indexing, so the first element of a list is at index 0. Python lists do not have a built-in first() method.

Q4. Which of the following creates a tuple with a single element?
  • A. t = (5)
  • B. t = (5,) ✓
  • C. t = [5]
  • D. t = {5}

Why: A trailing comma is required to create a single-element tuple, because parentheses alone are interpreted as grouping. (5) is just the integer 5, [5] is a list, and {5} is a set.

Q5. What does `my_dict.get('missing_key', 0)` return if 'missing_key' is not in the dictionary?
  • A. None
  • B. An KeyError is raised
  • C. 0 ✓
  • D. The string 'missing_key'

Why: The get() method returns the default value supplied as the second argument when the key is not found. Unlike square-bracket access, it does not raise a KeyError.

Module 5 Module 5: Introduction to NumPy

Introduction to NumPy

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. Which function is used to create a NumPy array from a Python list?
  • A. np.make_array()
  • B. np.array() ✓
  • C. np.list_to_array()
  • D. np.new()

Why: np.array() is the standard NumPy function that converts a Python list (or nested lists) into an ndarray object. The other options are not valid NumPy functions.

Q2. What does the shape attribute of a NumPy array return?
  • A. The total number of elements in the array
  • B. The data type of the elements
  • C. A tuple giving the size of each dimension ✓
  • D. The number of bytes used by the array

Why: The shape attribute returns a tuple where each value represents the length of the array along each dimension, such as (3, 4) for a 3-row, 4-column array. Total element count is given by size, and data type by dtype.

Q3. What will np.zeros((2, 3)) produce?
  • A. A 1D array with 6 zeros
  • B. A 2D array with 2 rows and 3 columns filled with zeros ✓
  • C. A 2D array with 3 rows and 2 columns filled with ones
  • D. An error, because zeros requires a single integer

Why: np.zeros() takes a shape tuple and returns an array filled with zeros of that shape. Passing (2, 3) creates a 2x3 two-dimensional array.

Q4. What is the result of the expression np.array([1, 2, 3]) * 2?
  • A. [2, 4, 6] ✓
  • B. [1, 2, 3, 1, 2, 3]
  • C. [1, 2, 3, 2]
  • D. An error, because arrays cannot be multiplied by integers

Why: NumPy supports vectorized operations, so multiplying an array by a scalar applies the operation to every element, producing [2, 4, 6]. Unlike Python lists, multiplying an array does not repeat its contents.

Q5. Which indexing expression selects the second row and all columns from a 2D array named arr?
  • A. arr[2]
  • B. arr[1, :] ✓
  • C. arr[:, 1]
  • D. arr[2, :]

Why: NumPy indices are zero-based, so the second row has index 1. The expression arr[1, :] selects row 1 across all columns. arr[:, 1] would select the second column instead.

Module 6 Module 6: Data Analysis with Pandas

Data Analysis with Pandas

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. Which Pandas data structure is used to represent a two-dimensional table with labeled rows and columns?
  • A. Series
  • B. DataFrame ✓
  • C. ndarray
  • D. Panel

Why: A DataFrame is Pandas' two-dimensional, tabular data structure with labeled rows (index) and columns. A Series is one-dimensional, and Panel was removed from modern Pandas.

Q2. Which function is used to read a CSV file into a Pandas DataFrame?
  • A. pd.load_csv()
  • B. pd.read_csv() ✓
  • C. pd.open_csv()
  • D. pd.import_csv()

Why: pd.read_csv() reads a comma-separated values file and returns a DataFrame. The other function names do not exist in the Pandas library.

Q3. What does df.head() return by default?
  • A. The last 5 rows of the DataFrame
  • B. The first 5 rows of the DataFrame ✓
  • C. The column names only
  • D. The total number of rows

Why: df.head() returns the first 5 rows by default. You can pass a number, such as df.head(10), to change how many rows are shown.

Q4. How do you select the column named 'price' from a DataFrame called df?
  • A. df.get('price', 'column')
  • B. df('price')
  • C. df['price'] ✓
  • D. df.price.select()

Why: Bracket notation df['price'] returns the 'price' column as a Series. Dot notation (df.price) also works when the column name is a valid identifier, but bracket notation is the most reliable.

Q5. Which method removes rows containing missing values (NaN) from a DataFrame?
  • A. df.fillna()
  • B. df.drop_nan()
  • C. df.dropna() ✓
  • D. df.remove_null()

Why: df.dropna() removes rows (by default) that contain missing values. df.fillna() replaces missing values instead of removing them, and the other two method names do not exist in Pandas.

Module 7 Module 7: Data Visualization with Matplotlib

Data Visualization with Matplotlib

Introduction

Core content I

Core content II

Core content III

Summary

Further learning

Knowledge check

Q1. Which function is used to import the pyplot module from Matplotlib with the conventional alias?
  • A. import matplotlib.pyplot as plt ✓
  • B. import pyplot from matplotlib as plt
  • C. from matplotlib import plot as plt
  • D. import matplotlib.graph as plt

Why: The conventional import is 'import matplotlib.pyplot as plt', which lets you call plotting functions using the short alias 'plt'. The other options use invalid import syntax or non-existent modules.

Q2. Which Matplotlib function creates a line plot from x and y values?
  • A. plt.bar()
  • B. plt.plot() ✓
  • C. plt.hist()
  • D. plt.scatter()

Why: plt.plot() draws lines connecting the data points given as x and y sequences. plt.bar() creates bar charts, plt.hist() creates histograms, and plt.scatter() draws individual points without connecting lines.

Q3. Which function displays the figure after all plotting commands have been issued?
  • A. plt.show() ✓
  • B. plt.display()
  • C. plt.render()
  • D. plt.draw_now()

Why: plt.show() renders and displays the current figure window or inline output. Matplotlib has no display(), render(), or draw_now() function in its pyplot interface.

Q4. Which function is used to add a label to the x-axis of a plot?
  • A. plt.xlabel() ✓
  • B. plt.xtitle()
  • C. plt.xname()
  • D. plt.axis_label_x()

Why: plt.xlabel() sets the text label for the x-axis. The other names do not exist in Matplotlib's pyplot interface.

Q5. Which keyword argument in plt.plot() is used to set the color of the line?
  • A. colour
  • B. color ✓
  • C. paint
  • D. fill

Why: The 'color' keyword argument (also accepted as 'c' in some contexts) sets the line color. Matplotlib uses American spelling, so 'colour' is not recognized as a valid argument for plt.plot().

Stay in the loop on this course.

We’ll email you when new modules or related material drops. No spam.

Built with Fragment Language. Sovereign architecture — no third-party trackers.
FragRun.mfgAFImemoryFGOwnership: B-Systems.ee