Certified Entry-Level Python Programmer Practice Test

Earning a Certified Entry-Level Python Programmer (PCEP) credential is a great way to validate your foundational knowledge in Python programming and stand out in the competitive tech industry. To help you get ready for the PCEP exam, we have prepared a set of 25 practice multiple-choice questions along with answers and explanations.

Before diving into the practice test below, you can also check out 50+ Python MCQ for Beginners.

1. What is the output of the following Python code?

print(5 // 2)
A) 2
B) 2.5
C) 3
D) Syntax Error

Answer:

A) 2

Explanation:

The // operator performs floor division, returning the largest possible integer.

2. Which of the following data types is immutable in Python?

A) List
B) Set
C) Dictionary
D) Tuple

Answer:

D) Tuple

Explanation:

Tuples in Python are immutable, meaning their elements cannot be changed after creation.

3. What is the purpose of the pass statement in Python?

A) To pass values between functions
B) To create a new class
C) To serve as a no-operation (NOP) instruction
D) To exit a loop

Answer:

C) To serve as a no-operation (NOP) instruction

Explanation:

The pass statement is a null operation; nothing happens when it executes. It is typically used as a placeholder.

4. How do you create a lambda function in Python?

A) lambda x: x + 1
B) function lambda x: x + 1
C) define lambda(x): return x + 1
D) lambda_function(x) => x + 1

Answer:

A) lambda x: x + 1

Explanation:

Lambda functions in Python are defined using the lambda keyword, followed by the parameters, a colon, and the expression.

5. Which of the following methods will remove the last item from a Python list and return it?

A) remove()
B) pop()
C) del
D) clear()

Answer:

B) pop()

Explanation:

The pop() method removes the last item from the list and returns it, whereas remove() deletes the first occurrence of a specified value.

6. Which of the following operators is used for exponentiation in Python?

A) ^
B) **
C) exp()
D) pow()

Answer:

B) **

Explanation:

The ** operator in Python is used for exponentiation.

7. What is the output of the following Python code?

my_str = "Hello, World!"
print(my_str[-1])
A) H
B) !
C) d
D) IndexError

Answer:

B) !

Explanation:

Negative indexing starts from the end of the string. my_str[-1] will output the last character !.

8. How can you get the length of a list my_list in Python?

A) len(my_list)
B) my_list.len()
C) length(my_list)
D) my_list.length()

Answer:

A) len(my_list)

Explanation:

The len() function is used to get the length of a list in Python.

9. Which of the following statements is True about Python sets?

A) Sets are mutable, and elements are ordered.
B) Sets are mutable, and elements are unordered.
C) Sets are immutable, and elements are ordered.
D) Sets are immutable, and elements are unordered.

Answer:

B) Sets are mutable, and elements are unordered.

Explanation:

Sets in Python are mutable, meaning you can change their content, but they are unordered, so they do not record element position.

10. Which Python library is specifically designed for data manipulation and analysis?

A) NumPy
B) SciPy
C) Matplotlib
D) Pandas

Answer:

D) Pandas

Explanation:

Pandas is a fast, powerful, and flexible open-source data analysis and manipulation tool built on top of the Python programming language.

11. What will the following code snippet output in Python?

for i in range(1, 5, 2):
    print(i, end=" ")
A) 1 3
B) 1 2 3 4
C) 0 2 4
D) 1 3 5

Answer:

A) 1 3

Explanation:

The range(1, 5, 2) generates numbers from 1 to 4 with a step of 2. Hence the output will be 1 and 3.

12. How can you handle exceptions in Python?

A) Using the try and except blocks
B) Using the catch keyword
C) Using the error handler
D) Using the exception function

Answer:

A) Using the try and except blocks

Explanation:

Python uses try and except blocks to handle exceptions. Code that might cause an exception is placed in the try block, and the handling of the exception is implemented in the except block.

13. Which of the following is the correct way to read a file myfile.txt in Python?

A) open('myfile.txt', 'r')
B) file.read('myfile.txt')
C) read.file('myfile.txt')
D) openfile('myfile.txt')

Answer:

A) open('myfile.txt', 'r')

Explanation:

The open() function is used to open a file in Python. The first argument is the filename, and the second argument is the mode, with 'r' representing reading mode.

14. What is the purpose of the __init__ method in Python classes?

A) To initialize static variables
B) To initialize the object’s attributes
C) To create class-level methods
D) To delete the object instances

Answer:

B) To initialize the object’s attributes

Explanation:

The __init__ method is called when an object is instantiated and is used to initialize the attributes of the object.

15. How do you define a function my_function in Python?

A) define my_function():
B) function my_function() {}
C) def my_function():
D) func my_function() -> None:

Answer:

C) def my_function():

Explanation:

Functions in Python are defined using the def keyword followed by the function name and parentheses.

16. Which of the following will correctly create a dictionary in Python?

A) my_dict = dict{1: 'apple', 2: 'banana'}
B) my_dict = {1: 'apple', 2: 'banana'}
C) my_dict = [1: 'apple', 2: 'banana']
D) my_dict = (1: 'apple', 2: 'banana')

Answer:

B) my_dict = {1: 'apple', 2: 'banana'}

Explanation:

Dictionaries in Python are created by placing elements inside curly braces{}`, separated by commas.

17. What is the default value of the step parameter in Python's range() function?

A) 0
B) 1
C) None
D) -1

Answer:

B) 1

Explanation:

The range() function in Python has a default step value of 1.

18. How can you concatenate two lists list1 and list2 in Python?

A) list1.concat(list2)
B) concat(list1, list2)
C) list1 + list2
D) list1.append(list2)

Answer:

C) list1 + list2

Explanation:

The + operator can be used to concatenate two lists in Python.

19. What will the enumerate() function return for a given list ['apple', 'banana', 'cherry']?

A) [(0, 'apple'), (1, 'banana'), (2, 'cherry')]
B) [('apple', 0), ('banana', 1), ('cherry', 2)]
C) {'apple': 0, 'banana': 1, 'cherry': 2}
D) ['apple', 'banana', 'cherry']

Answer:

A) [(0, 'apple'), (1, 'banana'), (2, 'cherry')]

Explanation:

The enumerate() function returns a sequence of tuples representing index and value pairs.

20. Which of the following methods can be used to add an element to a set in Python?

A) add()
B) append()
C) insert()
D) extend()

Answer:

A) add()

Explanation:

The add() method is used to add a single element to a set in Python.

21. Which Python library provides functions to work with dates and times?

A) math
B) time
C) datetime
D) calendar

Answer:

C) datetime

Explanation:

The datetime module supplies classes for working with dates and times, such as date arithmetic.

22. Which of the following Python code will correctly match an email address pattern using regular expressions?

import re
pattern = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
result = re.match(pattern, 'test@example.com')
A) True
B) False
C) None
D) Error

Answer:

B) False

Explanation:

re.match() checks for a match only at the beginning of the string. re.search() or re.fullmatch() should be used to search throughout the string.

23. How can you convert a bytes object b'Python' to a str object in Python?

A) str('Python')
B) 'Python'.decode('utf-8')
C) b'Python'.decode('utf-8')
D) str(b'Python', 'utf-8')

Answer:

C) b'Python'.decode('utf-8')

Explanation:

To convert a bytes object to a str object, you should use the decode() method.

24. Which of the following functions will return the ASCII value of a character?

A) ord()
B) chr()
C) ascii()
D) char()

Answer:

A) ord()

Explanation:

The ord() function returns an integer representing the Unicode character, which is the ASCII value for ASCII characters.

25. What will be the output of the following code snippet?

print(isinstance(1, object))
A) True
B) False
C) Error
D) None

Answer:

A) True

Explanation:

In Python, everything is an object, so isinstance(1, object) will return True as 1 is an instance of object.


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top