wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Exploring Python Fundamentals

Total questions: 20

Worksheet time: 15mins

Name
Class
Date
1.

What are the basic data types in Python?

a)

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

b)

char, byte, array, complex, frozenset, deque, range, memoryview

c)

string, number, object, function, boolean, array, symbol, set

d)

integer, decimal, character, boolean, list, map, tuple, string

2.

How do you create a list in Python?

a)

You create a list in Python using curly braces, e.g., my_list = {} or my_list = {1, 2, 3}.

b)

You create a list in Python by using parentheses, e.g., my_list = () or my_list = (1, 2, 3).

c)

You create a list in Python with the list() function, e.g., my_list = list() or my_list = list(1, 2, 3).

d)

You create a list in Python using square brackets, e.g., my_list = [] or my_list = [1, 2, 3].

3.

What is the output of 5 + 3 * 2?

a)

8

b)

11

c)

9

d)

10

4.

Explain the difference between a list and a tuple in Python.

a)

The main difference is that lists are mutable and tuples are immutable.

b)

Lists are faster than tuples in all operations.

c)

Tuples are used for dynamic data, whereas lists are for static data.

d)

Lists can contain only numbers, while tuples can contain any data type.

5.

How do you check if a number is even in Python?

a)

n - 2 == 0

b)

n % 2 == 0

c)

n % 3 == 0

d)

n / 2 == 1

6.

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

a)

To define a function in Python.

b)

To create loops for iteration.

c)

To declare variables in Python.

d)

To execute code conditionally based on a boolean expression.

7.

How do you create a dictionary in Python?

a)

A dictionary in Python is created with parentheses, for example: my_dict = ('key1', 'value1', 'key2', 'value2').

b)

You can create a dictionary in Python using curly braces, like this: my_dict = {'key1': 'value1', 'key2': 'value2'}.

c)

To create a dictionary in Python, use a list format, like this: my_dict = ['key1', 'value1', 'key2', 'value2'].

d)

You can create a dictionary in Python using square brackets, like this: my_dict = ['key1': 'value1', 'key2': 'value2'].

8.

How do you access the first element of a list?

a)

Access the first element with index -1 in a list.

b)

Use index 0 to access the first element of a list.

c)

Retrieve the first element using index 2 of a list.

d)

Use index 1 to access the first element of a list.

9.

What is the output of the expression 10 > 5?

a)

5 >= 10

b)

10 < 5

c)

false

d)

true

10.

What does the 'break' statement do in a loop?

a)

The 'break' statement exits a loop.

b)

The 'break' statement skips the current loop.

c)

The 'break' statement pauses a loop.

d)

The 'break' statement continues to the next iteration.

11.

How do you convert a string to an integer in Python?

a)

int('string')

b)

list('string')

c)

float('string')

d)

str('string')

12.

Who developed Python Programming Language?

a)

Wick van Rossum

b)

Rasmus Lerdorf

c)

Guido van Rossum

d)

Niene Stom

13.

Which of the following is the correct extension of the Python file?

a)

.python

b)

.pl

c)

.py

d)

.p

14.

Which of the following is the correct way to print "Hello, World!" in Python?

a)

print("Hello, World!")

b)

echo "Hello World!"

c)

System.out.print("Hello, World!")

d)

console.log("Hello, World!")

15.

Which data type is used to store a collection of key-value pairs in Python?

a)

List

b)

Tuple

c)

Dictionary

d)

Set

16.

Which data type is used to store textual data in Python?

a)

Integer

b)

Float

c)

Boolean

d)

String

17.

Which of the following is the correct syntax for a for loop in Python?

a)

for(i=0; i<5; i++)

b)

for i in range(5)

c)

for i to 5

d)

foreach i in range(5)

18.

What will be the output of the following code?

a)

0

1

2

b)

1

2

3

c)

0

1

2

3

d)

Infinite loop

19.

Which of the following is used to take input from the user in Python?

a)

read()

b)

scanf()

c)

input()

d)

gets()

20.

What is the output of the following code?

a)

<class 'float'>

b)

<class 'int'>

c)

<class 'str'>

d)

<class 'bool'>