

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A comprehensive set of questions and answers designed to help individuals prepare for the python institute's pcap (certified associate in python programming) and pcep (certified entry-level python programmer) certification exams. Each question is accompanied by a verified answer and a rationale, offering clear explanations and insights into the correct solutions. This resource is invaluable for anyone seeking to enhance their python knowledge and achieve certification, covering a wide range of fundamental python concepts and programming principles. The questions cover topics such as variable names, data types, operators, control flow, functions, and exception handling. This q&a is an excellent tool for self-assessment and exam preparation, ensuring a solid understanding of python essentials.
Typology: Exams
1 / 25
This page cannot be seen from the preview
Don't miss anything!


















Answer: C Rationale: The def keyword is used to declare functions.
12.Which function converts a string to an integer? A. str() B. float() C. chr() D. int() Answer: D Rationale: int() converts compatible strings into integers. 13.What is the output of print("Hello"[1])? A. H B. e C. l D. o Answer: B Rationale: Indexing starts at 0; index 1 is the second character. 14.Which loop is guaranteed to execute at least once? A. for B. while C. do-while D. None Answer: D Rationale: Python does not have a do-while loop. 15.Which keyword stops a loop prematurely? A. exit B. stop C. break D. end Answer: C Rationale: break exits the nearest enclosing loop. 16.What is the result of list(range(3))? A. [1,2,3] B. [0,1,2]
D. Error Answer: B Rationale: range(3) generates values from 0 up to but not including 3. 17.Which symbol is used for comments? A. // B. C. # D. /* */ Answer: C Rationale: Python uses # for single-line comments. 18.What is the output of print(type([]))? A. <class 'array'> B. <class 'tuple'> C. <class 'list'> D. <class 'set'> Answer: C Rationale: Square brackets create a list. 19.Which keyword is used to return a value from a function? A. yield B. send C. return D. back Answer: C Rationale: return sends a value back to the caller. 20.What is the output of print(10 % 3)? A. 1 B. 3 C. 0 D. 10
Answer: D Rationale: print() outputs text to standard output. 25.Which operator checks object identity? A. == B. = C. is D. equals Answer: C Rationale: is checks whether two variables reference the same object. 26.What is the output of print("a" * 3)? A. a B. aaa C. a a a D. Error Answer: B *Rationale: String repetition is supported using *.* 27.Which exception is raised when dividing by zero? A. ValueError B. TypeError C. ZeroDivisionError D. ArithmeticError Answer: C Rationale: Division by zero raises ZeroDivisionError. 28.What does continue do in a loop? A. Stops the loop B. Skips current iteration C. Restarts program D. Ends iteration permanently
Answer: B Rationale: continue skips to the next loop iteration. 29.Which keyword is used to create a class? A. object B. class C. define D. struct Answer: B Rationale: Classes are defined using the class keyword. 30.What is the output of print(len("Python"))? A. 5 B. 6 C. 7 D. Error Answer: B Rationale: The string "Python" has six characters. 31.Which method adds an element to a list? A. add() B. append() C. insert() D. Both B and C Answer: D Rationale: Both methods add elements to a list in different ways. 32.What does pass do? A. Ends program B. Skips execution C. Acts as a placeholder D. Raises error Answer: C
Answer: D Rationale: Lists can be modified after creation. 37.What does del do? A. Deletes files B. Deletes variables or objects C. Ends program D. Clears memory Answer: B Rationale: del removes references to objects. 38.What is the default return value of a function with no return statement? A. 0 B. False C. None D. Error Answer: C Rationale: Functions return None by default. 39.Which operator has the highest precedence? A. + B. * C. ** D. = Answer: C Rationale: Exponentiation has the highest precedence. 40.Which statement creates a tuple with one element? A. t = (1) B. t = (1,) C. t = [1] D. t = {1} Answer: B Rationale: A trailing comma is required for single-element tuples.
41.Which module is used for mathematical functions? A. math B. calc C. numeric D. statistics Answer: A Rationale: The math module provides mathematical functions. 42.What is the output of print(bool("False"))? A. False B. True C. None D. Error Answer: B Rationale: Non-empty strings evaluate to True. 43.Which function returns both index and value when looping? A. range() B. zip() C. enumerate() D. map() Answer: C Rationale: enumerate() provides index-value pairs. 44.Which keyword creates an anonymous function? A. def B. lambda C. anon D. func Answer: B Rationale: Lambda functions are anonymous functions.
49.Which loop is best when number of iterations is known? A. while B. for C. do-while D. repeat Answer: B Rationale: for loops are ideal for known iteration counts. 50.What does sorted() return? A. None B. Iterator C. New sorted list D. Tuple Answer: C Rationale: sorted() returns a new sorted list. 51.Which file mode opens a file for reading? A. w B. a C. r D. x Answer: C Rationale: r is read mode. 52.What does with open() ensure? A. Faster execution B. File auto-closing C. File encryption D. File locking Answer: B Rationale: Context managers automatically close files.
53.Which statement creates a set? A. s = {} B. s = [] C. s = set() D. s = () Answer: C Rationale: Empty sets must be created using set(). 54.Which keyword checks multiple conditions? A. elif B. else C. if D. switch Answer: A Rationale: elif allows multiple conditional checks. 55.What does help() do? A. Exits Python B. Displays documentation C. Compiles code D. Debugs code Answer: B Rationale: help() shows documentation. 56.Which function returns ASCII code? A. ascii() B. ord() C. chr() D. code() Answer: B Rationale: ord() returns the ASCII/Unicode code.
61.What is the output of print(len(set([1,1,2,2])))? A. 2 B. 4 C. 1 D. Error Answer: A Rationale: Sets remove duplicates. 62.Which operator concatenates lists? A. * B. + C. & D. join Answer: B Rationale: + concatenates lists. 63.What is the output of print(type(None))? A. <class 'null'> B. <class 'void'> C. <class 'NoneType'> D. None Answer: C Rationale: None has type NoneType. 64.Which statement defines inheritance? A. class A extends B B. class A(B) C. class A inherits B D. class A:B Answer: B Rationale: Python uses parentheses for inheritance. 65.Which keyword creates a generator? A. return B. yield
C. generate D. next Answer: B Rationale: yield creates generator functions. 66.What does isinstance(x, int) return? A. int B. type C. True or False D. None Answer: C Rationale: It checks type membership. 67.Which operator is used for string formatting (old style)? A. + B. % C. format D. f Answer: B Rationale: % is used in old-style formatting. 68.What does globals() return? A. Local variables B. Global namespace dictionary C. Module list D. Function list Answer: B Rationale: It returns a dictionary of global symbols. 69.Which built-in function converts an iterable to a list? A. tuple() B. array() C. list()
Answer: A Rationale: global allows modifying global variables. 74.Which function returns the smallest value? A. small() B. min() C. low() D. least() Answer: B Rationale: min() returns the minimum value. 75.What does nonlocal refer to? A. Global scope B. Local scope C. Enclosing function scope D. Module scope Answer: C Rationale: nonlocal refers to variables in enclosing scopes. 76.What is the output of print(bool([]))? A. True B. False C. None D. Error Answer: B Rationale: Empty containers evaluate to False. 77.Which statement checks for membership in a dictionary key? A. key in dict B. dict.has(key) C. dict[key] D. find(key)
Answer: A Rationale: in checks keys by default. 78.Which method returns dictionary keys? A. keys() B. values() C. items() D. get() Answer: A Rationale: keys() returns all dictionary keys. 79.Which operator is used for logical OR? A. | B. || C. or D. plus Answer: C Rationale: or is the logical OR operator. 80.What is the output of print(5 == True)? A. True B. False C. Error D. None Answer: B Rationale: True equals 1, not 5. 81.Which statement creates a shallow copy of a list? A. list.copy() B. list[:] C. copy.copy() D. All of the above