wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Mastering Python Programming Concepts

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What are the built-in data types in Python?

a)

str, list, map, tuple

b)

int, float, array, set

c)

int, float, complex, list, tuple, range, str, dict, set, frozenset, bool, bytes, bytearray, memoryview

d)

char, float, list, dict

2.

How do you define a list in Python?

a)

A list in Python is defined using curly braces, e.g., {1, 2, 3}.

b)

A list in Python is defined using parentheses, e.g., (1, 2, 3).

c)

A list in Python is defined using square brackets, e.g., [1, 2, 3].

d)

A list in Python is defined using angle brackets, e.g., <1, 2, 3>.

3.

What is the difference between a tuple and a list?

a)

A tuple can change size, while a list cannot.

b)

A tuple is ordered, while a list is unordered.

c)

A tuple is immutable, while a list is mutable.

d)

A tuple is a list, while a list is a tuple.

4.

What keyword is used to create a function in Python?

a)

function

b)

create

c)

def

d)

method

5.

How do you handle exceptions in Python?

a)

Utilize print statements to debug exceptions in Python.

b)

Implement error handling with switch-case structures.

c)

Use try-except blocks to handle exceptions in Python.

d)

Use if-else statements to manage exceptions in Python.

6.

What is the purpose of the 'if' statement in Python?

a)

The purpose of the 'if' statement in Python is to execute code conditionally based on a boolean expression.

b)

The 'if' statement in Python is meant for importing modules.

c)

The 'if' statement in Python is for creating loops.

d)

The 'if' statement in Python is used to define functions.

7.

Explain the use of 'for' loops in Python.

a)

'for' loops in Python are used to iterate over sequences or iterables, executing a block of code for each item.

b)

'for' loops in Python are used to define functions and methods.

c)

'for' loops in Python are utilized to handle exceptions and errors.

d)

'for' loops in Python are primarily for creating classes and objects.

8.

What is a dictionary in Python?

a)

A dictionary in Python is a single key-value pair.

b)

A dictionary in Python is a collection of key-value pairs.

c)

A dictionary in Python is a type of list.

d)

A dictionary in Python is a collection of ordered items.

9.

How do you import a module in Python?

a)

import module_name

b)

require module_name

c)

include module_name

d)

load module_name

10.

What is the difference between a function and a method in Python?

a)

A function is a type of method in Python.

b)

A method can exist independently of an object.

c)

Functions are always defined within classes in Python.

d)

A function is independent, while a method is associated with an object.

11.

What is inheritance in object-oriented programming?

a)

Inheritance allows a class to override methods from its parent class.

b)

Inheritance enables a superclass to access private members of a subclass.

c)

Inheritance allows a subclass to inherit attributes and methods from a superclass.

d)

Inheritance is a method to encapsulate data within a class.

12.

How do you create a class in Python?

a)

class ClassName: def __init__(self): pass

b)

class ClassName[]:

c)

def ClassName():

d)

class ClassName() {}

13.

What is the purpose of the 'try' and 'except' blocks?

a)

They are meant to improve code readability and structure.

b)

The 'try' and 'except' blocks are used for defining functions.

c)

The purpose is to optimize performance in code execution.

d)

The purpose of 'try' and 'except' blocks is to handle exceptions and errors in a controlled manner.

14.

What is a lambda function in Python?

a)

A lambda function is a small anonymous function defined with the 'lambda' keyword.

b)

A lambda function is a built-in data structure in Python.

c)

A lambda function is a method for defining classes in Python.

d)

A lambda function is a type of loop in Python.

15.

How do you define a default parameter in a function?

a)

You define a default parameter by using the syntax 'parameterName = defaultValue' in the function definition.

b)

A default parameter is created by declaring 'parameterName' without any value in the function signature.

c)

You define a default parameter by assigning 'defaultValue' to 'parameterName' after the function call.

d)

You can set a default parameter by placing 'defaultValue' before 'parameterName' in the function header.

16.

What is polymorphism in Python?

a)

Polymorphism is the ability to present the same interface for different data types in Python.

b)

Polymorphism is a method for optimizing memory usage in Python.

c)

Polymorphism is the process of converting data types in Python.

d)

Polymorphism refers to the ability to create multiple classes in Python.

17.

What is the significance of the 'self' parameter in class methods?

a)

The 'self' parameter allows for static method access in classes.

b)

The 'self' parameter is used for defining class-level attributes.

c)

The 'self' parameter is optional and can be omitted in methods.

d)

The 'self' parameter is essential for accessing instance attributes and methods within class methods.

18.

How do you raise an exception in Python?

a)

raise Exception('Error message')

b)

raise Exception('Message error')

c)

raise Error('Error message')

d)

throw Exception('Error message')

19.

What is the difference between '==' and 'is' in Python?

a)

The '==' operator checks for value equality, while 'is' checks for object identity.

b)

The '==' operator checks for reference equality, while 'is' checks for value identity.

c)

The '==' operator checks for object identity, while 'is' checks for value equality.

d)

The '==' operator compares types, while 'is' compares values.

20.

How can you read a file in Python?

a)

Use open('filename', 'r') to read a file.

b)

Use read('filename') to access a file.

c)

Employ open('filename') without mode to read.

d)

Utilize readfile('filename') for file reading.