Learn Mode

Python Programming Concepts Quiz

#1

What does the 'print' function do in Python?

It displays output to the console.
Explanation

Displays output.

#2

Which of the following is NOT a valid variable name in Python?

2nd_variable
Explanation

Invalid variable name.

#3

What is the output of the following code snippet?

x = 10
y = 5
print(x % y)

0
Explanation

Modulo operation result.

#4

Which of the following data types is mutable in Python?

List
Explanation

Mutable data type.

#5

What is the output of the following code snippet?

x = [1, 2, 3]
print(x[1:])

[2, 3]
Explanation

Slices list from index 1 onwards.

#6

Which of the following statements is used to exit a loop in Python?

break
Explanation

Exit loop statement.

#7

What is the result of the following expression in Python: 5 // 2?

2
Explanation

Floor division result.

#8

Which keyword is used to define a function in Python?

def
Explanation

Function definition keyword.

#9

What will be the output of the following code snippet?

x = 5
y = 2
print(x ** y)

25
Explanation

Exponentiation.

#10

Which of the following is a correct way to open a file named 'data.txt' for writing in Python?

open('data.txt', 'w')
Explanation

File open for writing.

#11

What will be the output of the following code snippet?

print(3 * '7')

'777'
Explanation

Repeats '7' three times.

#12

Which of the following is used to comment multiple lines in Python?

''' '''
Explanation

Multi-line comment syntax.

#13

What does the 'pass' statement do in Python?

It is a placeholder for future code.
Explanation

Placeholder statement.

#14

What is the purpose of the 'global' keyword in Python?

To access variables defined outside the current function.
Explanation

Access global variables.

#15

What does the 'with' statement do in Python?

It is used to define a context manager.
Explanation

Context manager definition.

#16

Which of the following is true about Python's 'lambda' functions?

They are anonymous and can be used inline.
Explanation

Anonymous inline functions.

#17

What is the purpose of the 'finally' block in Python exception handling?

To execute code whether an exception occurs or not
Explanation

Executes code regardless of exception.

#18

Which method is used to remove the last element from a list in Python?

pop()
Explanation

Removes last element.

#19

Which of the following is NOT a valid way to open a file in Python?

file = open('data.txt', 'r+b')
Explanation

Invalid file open mode.

#20

What is the purpose of 'try' and 'except' in Python?

To handle exceptions
Explanation

Exception handling.

#21

What is the output of the following code snippet?

x = [1, 2, 3]
print(x.pop())

3
Explanation

Removes and returns last element.

#22

What is the output of the following code snippet?

print(len('Hello'))

5
Explanation

Length of the string.

#23

What is the output of the following code snippet?

print(10 * 3 + 5 == 35)

True
Explanation

Comparison expression.

#24

What is the output of the following code snippet?

x = 10
y = 20
print(x > 5 and y < 30)

True
Explanation

Logical expression.

Test Your Knowledge

Craft your ideal quiz experience by specifying the number of questions and the difficulty level you desire. Dive in and test your knowledge - we have the perfect quiz waiting for you!