Python Practice Exam: Questions and Answers, Exams of Technology

A practice exam for python programming, including multiple-choice questions and detailed explanations for each answer. It covers fundamental concepts such as data types, operators, control flow, and string manipulation. This resource is designed to help students test their knowledge and prepare for exams or assessments in python programming. It includes questions on variable names, numeric types, logical operators, and string methods, offering a comprehensive review of basic python concepts. The practice exam is suitable for beginners and intermediate learners looking to reinforce their understanding of python syntax and programming principles. It also covers control flow statements, loop structures, and string manipulation techniques, providing a well-rounded assessment of python fundamentals.

Typology: Exams

2025/2026

Available from 12/30/2025

shilpi-jain-1
shilpi-jain-1 šŸ‡®šŸ‡³

4.2

(5)

29K documents

1 / 91

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Python Practice Exam
Question 1. Which of the following is true about Python's execution model?
A) Python source code is directly executed by hardware
B) Python source code is first compiled to bytecode, which is then interpreted
C) Python source code is always compiled into machine code
D) Python does not use bytecode at all
Answer: B
Explanation: Python code is compiled to bytecode, which the interpreter executes; it is not direct
machine code.
Question 2. What does the `print()` function do in Python?
A) Reads input from the user
B) Writes output to the console
C) Opens a file
D) Terminates the program
Answer: B
Explanation: The `print()` function displays output to the console.
Question 3. Which of the following is a valid variable name according to PEP 8?
A) 1variable
B) variable_1
C) variable-1
D) variable 1
Answer: B
Explanation: Variable names must start with a letter or underscore and not contain spaces or hyphens.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b

Partial preview of the text

Download Python Practice Exam: Questions and Answers and more Exams Technology in PDF only on Docsity!

Question 1. Which of the following is true about Python's execution model? A) Python source code is directly executed by hardware B) Python source code is first compiled to bytecode, which is then interpreted C) Python source code is always compiled into machine code D) Python does not use bytecode at all Answer: B Explanation: Python code is compiled to bytecode, which the interpreter executes; it is not direct machine code. Question 2. What does the print() function do in Python? A) Reads input from the user B) Writes output to the console C) Opens a file D) Terminates the program Answer: B Explanation: The print() function displays output to the console. Question 3. Which of the following is a valid variable name according to PEP 8? A) 1variable B) variable_ C) variable- 1 D) variable 1 Answer: B Explanation: Variable names must start with a letter or underscore and not contain spaces or hyphens.

Question 4. What is the output type of the expression input("Enter value: ")? A) int B) float C) str D) bool Answer: C Explanation: The input() function always returns a string. Question 5. Which of the following is NOT a core numeric type in Python? A) int B) float C) double D) complex Answer: C Explanation: Python does not have a double type; it uses float for decimal numbers. Question 6. How would you convert a string "123" to an integer in Python? A) str("123") B) int("123") C) float("123") D) bool("123")

C) 3

D) 0

Answer: B Explanation: // is floor division, which returns the quotient without the remainder. Question 10. What is the output of True and False? A) True B) False C) 1 D) 0 Answer: B Explanation: The logical and returns True only if both operands are True. Question 11. Which of the following statements assigns 10 to variable x and then adds 5 to it? A) x = 10 + 5 B) x = 10; x += 5 C) x = 10 * 5 D) x = 10; x =+ 5 Answer: B Explanation: x += 5 adds 5 to the current value of x. Question 12. What is the result of ~2 in Python?

A) 1

B) - 2

C) - 3

D) 3

Answer: C Explanation: ~ is bitwise NOT; for integers, ~n = - (n+1), so ~2 = - 3. Question 13. Which comparison operator checks for inequality? A) == B) != C) >= D) <= Answer: B Explanation: != checks if two values are not equal. Question 14. What does the expression not 0 evaluate to? A) True B) False C) 0 D) None Answer: A Explanation: not inverts the truth value; 0 is falsy, so not 0 is True.

Explanation: The ^ operator performs bitwise exclusive OR. Question 18. What is the output of print("Hello" + "World")? A) HelloWorld B) Hello World C) Hello+World D) Error Answer: A Explanation: The + operator concatenates strings without any space. Question 19. Which statement correctly starts a conditional block in Python? A) if x = 5: B) if x == 5 C) if x == 5: D) if x: == 5 Answer: C Explanation: A colon : is required at the end of the conditional statement. Question 20. What is the purpose of indentation in Python control flow? A) It is optional B) It defines code blocks C) It is only for readability

D) It separates variables Answer: B Explanation: Indentation is mandatory in Python and defines the scope of code blocks. Question 21. What is the output of this code?

if 3 > 2: print("Yes") else: print("No") 

A) Yes B) No C) 3 D) 2 Answer: A Explanation: Since 3 is greater than 2, "Yes" is printed. Question 22. Which keyword is used for multiple conditions in Python control flow? A) else B) elif C) elseif D) then

B) 1 2 3

C) 3 2 1

D) 0 1 2 3

Answer: A Explanation: range(3) generates 0, 1, and 2. Question 25. Which function generates a sequence of numbers in Python? A) number() B) sequence() C) range() D) enumerate() Answer: C Explanation: The range() function creates a sequence of numbers. Question 26. What is the output of the following loop?

i = 0 while i < 3: print(i) i += 1 

A) 0 1 2 B) 1 2 3

C) 3 2 1

D) 0 1 2 3

Answer: A Explanation: The loop prints 0, 1, and 2 while incrementing i until it reaches 3. Question 27. Which statement is used to exit a loop prematurely? A) exit B) continue C) break D) stop Answer: C Explanation: The break statement immediately exits the loop. Question 28. What does the continue statement do in a loop? A) Exits the loop B) Skips to next iteration C) Stops execution D) Returns a value Answer: B Explanation: continue skips the rest of the current iteration and proceeds to the next. Question 29. Which statement is used as a placeholder in Python?

C) divide() D) partition() Answer: B Explanation: The split() method divides a string into a list of substrings. Question 32. How do you access the first character of a string s? A) s[0] B) s(0) C) s{0} D) s<0> Answer: A Explanation: Square brackets are used for indexing. Question 33. What is the output of "Python".upper()? A) python B) PYTHON C) Python D) error Answer: B Explanation: The upper() method converts all letters to uppercase. Question 34. Which string method removes whitespace from both ends?

A) strip() B) lstrip() C) rstrip() D) clean() Answer: A Explanation: strip() removes whitespace from both ends of a string. Question 35. How do you check if a string starts with a particular substring? A) startswith() B) begins() C) checkstart() D) isstart() Answer: A Explanation: The startswith() method checks if a string starts with a specified substring. Question 36. Which operator checks for membership in a string? A) == B) in C) is D) includes Answer: B Explanation: The in operator checks if a substring exists in a string.

Explanation: f-strings use curly braces to insert values. Question 40. What is the output of len("Python")? A) 5 B) 6 C) 7 D) 8 Answer: B Explanation: The string "Python" consists of 6 characters. Question 41. How do you create an empty list? A) list[] B) [] C) {} D) () Answer: B Explanation: Square brackets [] denote an empty list. Question 42. Which method adds an element to the end of a list? A) add() B) insert() C) append()

D) push() Answer: C Explanation: append() adds an element at the end of a list. Question 43. How do you remove the last element from a list? A) pop() B) remove() C) delete() D) discard() Answer: A Explanation: pop() removes and returns the last element. Question 44. What does the del statement do to a list element? A) Adds an element B) Deletes an element C) Returns an element D) Sorts the list Answer: B Explanation: del deletes an element at a specified index. Question 45. How do you access the third element of a list lst? A) lst[3]

Question 48. Which method reverses the order of elements in a list? A) reverse() B) invert() C) flip() D) turn() Answer: A Explanation: reverse() reverses the elements of a list in place. Question 49. What is a list comprehension? A) A way to define functions B) A concise way to create lists C) A debugging tool D) A sorting algorithm Answer: B Explanation: List comprehensions provide a concise way to generate lists. Question 50. How do you access an element in a nested list? A) list[i][j] B) list(i)(j) C) list{i,j} D) list[i.j] Answer: A Explanation: Use multiple indices for nested lists.

Question 51. What is the main difference between lists and tuples? A) Tuples are mutable B) Lists are immutable C) Tuples are immutable D) Lists cannot be indexed Answer: C Explanation: Tuples cannot be changed after creation; lists can. Question 52. How do you create a tuple with one element? A) (1) B) (1,) C) [1] D) {1} Answer: B Explanation: A comma is required to create a single-element tuple. Question 53. Which method unpacks a tuple into individual variables? A) unpack() B) split() C) assignment D) distribute()