Back to Learning Hub

Day 4: Local vs Global Variables, Functions & Data Types

20 questions • Select the best answer for each question

Question 1

What is the main purpose of a function in Python?

Question 2

What will be the output? def greet(): print("Hello") greet()

Question 3

What will happen when this code runs? def test(): x = 10 print(x)

Question 4

What will be the output? x = 5 def show(): x = 10 print(x) show() print(x)

Question 5

Why does a variable inside a function not affect the global one by default?

Question 6

What will be the output? x = 1 def change(): global x x = 10 change() print(x)

Question 7

Using global inside functions is generally discouraged because:

Question 8

Which of the following is a complex number?

Question 9

Which data type is IMMUTABLE?

Question 10

Which of the following can be modified after creation?

Question 11

What is the output? data = {"a": 1, "b": 2} print(data["b"])

Question 12

What does a function return if no return statement is used?

Question 13

What will this print? print(type(True))

Question 14

What will be the output? nums = [1, 2, 3] nums = tuple(nums) print(type(nums))

Question 15

What is the output? r = range(3) print(list(r))

Question 16

What is the key difference between set and frozenset?

Question 17

Which of the following represents a bytes object?

Question 18

Why can the random module help explain variable behavior?

Question 19

Why does misunderstanding scope cause bugs?

Question 20

What is the biggest takeaway from understanding scope and data types?