wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Fundamentals of Python Programming

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What are the basic data types in Python?

a)

int, float, str, bool, list, tuple, dict

b)

int, float, str, array

c)

bool, dict, string, number

d)

char, float, set, list

2.

How do you declare a variable in Python?

a)

let variable_name = value

b)

var variable_name = value

c)

variable_name : value

d)

You declare a variable in Python by using the syntax: variable_name = value.

3.

What is the purpose of an if statement in Python?

a)

To repeat code multiple times.

b)

To define a function in Python.

c)

To create a loop for iteration.

d)

To execute code conditionally based on a boolean expression.

4.

Explain the use of for loops in Python.

a)

For loops can only iterate over numbers in Python.

b)

For loops in Python are used to create classes.

c)

For loops in Python are used to define functions.

d)

For loops in Python allow iteration over sequences and execute a block of code for each item.

5.

How do you read a file in Python?

a)

Use 'readfile("filename.txt")' to read a file in Python.

b)

Read a file by calling 'file.read()' directly without opening it.

c)

Use 'open(file.txt)' to read a file in Python.

d)

Use 'with open("filename.txt", "r") as file: content = file.read()' to read a file in Python.

6.

What is the difference between 'read' and 'readlines' methods?

a)

The 'read' method reads a file line by line; 'readlines' reads the entire file at once.

b)

The 'read' method can only be used on text files; 'readlines' can be used on binary files.

c)

Both 'read' and 'readlines' return the same type of data.

d)

The 'read' method returns a single string; 'readlines' returns a list of strings.

7.

What is exception handling in Python?

a)

Exception handling is done using 'if' statements in Python.

b)

Exception handling in Python is a way to manage errors using 'try' and 'except' blocks.

c)

Exception handling in Python is only for syntax errors.

d)

Python does not support exception handling.

8.

How do you raise an exception in Python?

a)

throw ExceptionType('Error message')

b)

raise 'Error message'

c)

raise ExceptionType

d)

raise ExceptionType('Error message')

9.

What are lists and tuples in Python?

a)

Tuples can be modified after creation, while lists cannot.

b)

Both lists and tuples are mutable sequences in Python.

c)

Lists are mutable sequences, while tuples are immutable sequences in Python.

d)

Lists are immutable sequences, while tuples are mutable sequences in Python.

10.

How do you access elements in a dictionary?

a)

Access elements using dictionary::key.

b)

Use dictionary[key] or dictionary.get(key) to access elements.

c)

Use dictionary.key to access elements.

d)

Call dictionary.access(key) to retrieve values.