Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Challenging Python Concepts

Total questions: 38

Worksheet time: 19mins

Name
Class
Date
1.

What is the correct way to declare a variable in Python?

a)

x = 10

b)

let x = 10

c)

x := 10

d)

var x : int = 10

2.
a)

Completed

b)

No output

c)

0 1 2 3 4 Completed

d)

Error

3.
a)

30

b)

24

c)

20

d)

18

4.
a)

1 2 3 4 5

b)

1 3 5

c)

2 4

d)

Infinite loop

5.

a = 2

b = 3

c = 4

print(a + b * c * a // b)

a)

10

b)

14

c)

8

d)

18

6.

Which of the following is not a basic operator in Python?

a)

multiply()

b)

subtract()

c)

add()

d)

print()

7.

What data type is used to represent decimal numbers in Python?

a)

boolean

b)

string

c)

integer

d)

float and decimal.Decimal

8.
a)

7

b)

5

c)

ERROR

d)

6

9.

How do you create a block of code in Python?

a)

Use indentation to define a block of code.

b)

Use curly braces to define a block of code.

c)

Use semicolons to separate code blocks.

d)

Write all code in a single line without indentation.

10.

What will be the output of the expression 5 + 3 * 2?

a)

11

b)

10

c)

8

d)

16

11.
a)

40

b)

30

c)

35

d)

25

12.

Which of the following is a valid way to declare an integer variable?

a)

integer variableName;

b)

int variableName;

c)

float variableName;

d)

var variableName: int;

13.

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

a)

To create a loop that iterates over a list.

b)

To define a function in Python.

c)

To execute code conditionally based on a boolean expression.

d)

To import modules into a Python script.

14.

How do you iterate over a list using a for loop?

a)

foreach item in my_list do

b)

for item in my_list:

c)

for each item in my_list:

d)

for item from my_list:

15.

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

a)

In Python, '==' checks for value equality, while '===' does not exist.

b)

'===' is a valid operator in Python for comparing objects.

c)

Both '==' and '===' are used for strict comparison in Python.

d)

'==' checks for type equality, while '===' checks for value equality.

16.

How can you check if a variable is of type float?

a)

Use type(variable) == 'float' to check the variable type.

b)

Check if variable is a float by using variable.is_float() method.

c)

Use variable == float to determine if it's a float.

d)

Use isinstance(variable, float) to check if a variable is of type float.

17.

What will the following code print: for i in range(3): print(i)?

a)

-1, 0, 1

b)

0, 1, 2

c)

0 1 2

d)

1, 2, 3

18.

What is the purpose of the 'continue' statement in a loop?

a)

To skip the current iteration of a loop and continue with the next one.

b)

To pause the loop for a specified duration.

c)

To repeat the current iteration of a loop.

d)

To terminate the loop immediately and exit.

19.

How do you declare a list in Python?

a)

my_list: [1, 2, 3]

b)

list my_list = [1, 2, 3]

c)

my_list = (1, 2, 3)

d)

my_list = [1, 2, 3]

20.

What will happen if you use 'break' inside a while loop?

a)

The while loop will terminate immediately.

b)

The while loop will skip the next iteration.

c)

The while loop will pause for a moment.

d)

The while loop will continue indefinitely.

21.

How do you create a dictionary in Python?

a)

Dictionaries are 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)

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

d)

To create a dictionary, use the dict() function: my_dict = dict(key1='value1', key2='value2').

22.

What is the output of the expression len('Hello')?

a)

6

b)

4

c)

Hello

d)

5

23.

What is the result of 10 // 3 in Python?

a)

2

b)

5

c)

3

d)

4

24.

How do you use an 'else' statement with a for loop?

a)

Place 'else' inside the for loop to execute code after each iteration.

b)

The 'else' statement cannot be used with a for loop in Python.

c)

Use 'else' before the for loop to execute code if the loop did not encounter a 'break'.

d)

Use 'else' after the for loop to execute code if the loop did not encounter a 'break'.

25.

What is the significance of indentation in Python?

a)

Indentation is significant in Python as it defines code blocks and enforces readability.

b)

Indentation is used to define variable types in Python.

c)

Indentation is only used for comments in Python code.

d)

Indentation is optional in Python and has no effect on code execution.

26.

How can you check if a variable is of type string?

a)

Use isinstance(variable, str) to check if a variable is of type string.

b)

Use variable == str to determine if it's a string.

c)

Check if variable is a string by using variable.is_string() method.

d)

Use type(variable) == 'string' to check the variable type.

27.

How do you remove a key from a dictionary in Python?

a)

Both options 1 and 3 are correct.

b)

Use my_dict.pop('key') to remove a key and return its value.

c)

Use my_dict.remove('key') to delete a key from a dictionary.

d)

Use del my_dict['key'] to remove a key from a dictionary.

28.

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

a)

To create an empty function or class.

b)

To raise an exception in the code.

c)

To skip the current iteration of a loop.

d)

To terminate a loop immediately.

29.

What will be the output of the expression 10 % 3?

a)

3

b)

1

c)

0

d)

10

30.

How do you concatenate two strings in Python?

a)

Use the & operator to concatenate strings.

b)

Use the join() function to concatenate strings.

c)

Use the concat() method to join strings.

d)

Use the + operator to concatenate strings.

31.

What is the purpose of the 'return' statement in a function?

a)

To define a function without returning any value.

b)

To pause the function execution temporarily.

c)

To create a loop within the function.

d)

To exit a function and return a value to the caller.

32.

How can you check if a variable is of type list?

a)

Use isinstance(variable, list) to check if a variable is of type list.

b)

Use type(variable) == 'list' to check the variable type.

c)

Use variable == list to determine if it's a list.

d)

Check if variable is a list by using variable.is_list() method.

33.

What will be the output of the expression 2 ** 3?

a)

6

b)

5

c)

8

d)

9

34.

How do you create a tuple in Python?

a)

my_tuple = <1, 2, 3>

b)

my_tuple = [1, 2, 3]

c)

my_tuple = (1, 2, 3)

d)

my_tuple = {1, 2, 3}

35.

What will be the output of the expression 4 * (2 + 3)?

a)

20

b)

15

c)

12

d)

8

36.

How do you define a function in Python?

a)

define my_function():

b)

my_function() = function:

c)

def my_function():

d)

function my_function():

37.

What is the output of the expression 'Hello' + ' World'?

a)

Hello + World

b)

HelloWorld

c)

Hello World

d)

World Hello

38.

coding-output

a)

python

b)

pythn

c)

pyon

d)

pthn