- 1. What method is used to append an item to the end of a list?
A) insert() B) append() C) extend() D) add()
- 2. This Used to simplify resource management, especially for handling external resources like files, network connections, or database connections. It ensures that resources are properly initialized and released, even if an exception occurs during their use.
A) Cleaning up Exception B) Exception handling C) With statement D) Exception Management
- 3. How can you insert an element at a specific index in a list?
A) insert() B) extend() C) add() D) append()
- 4. This Removes and returns the element at a specified index.
A) remove() B) discard() C) pop() D) delete()
- 5. In Python, how can you add a new key-value pair to a dictionary?
A) Using assignment() B) Using insert() C) Using update() D) Using add()
- 6. This is a concept in programming, including Python, where the evaluation of a logical expression stops as soon as the result can be determined.
A) Sequential evaluation B) Direct evaluation C) Premature termination D) Short-circuit evaluation
- 7. How can you sort a list of strings in reverse order in Python?
A) sorted_list = sorted(my_list, reverse=True) B) sorted_list = sort(my_list) C) sorted_list = sorted(my_list) D) sorted_list = sort(my_list, reverse=True)
- 8. This is also known as an anonymous function, This allows you to create a function on-the-fly without having to formally define it using def
A) Enumerate function B) map function C) lambda function D) def function
- 9. How is a function defined in Python?
A) Using the define keyword B) Using the define function C) Using the def keyword D) Using the function keyword
- 10. A string that enclosed in triple quotes that provides documentation for a function
A) Docstring B) Parameters C) Arguments D) Scope
- 11. What is the purpose of the enumerate() function in Python?
A) To count the total number of elements in a list B) To iterate over both the elements and their indices in a list C) To reverse the order of elements in a list D) To remove specific elements from a list
- 12. How can you remove an element from a set without raising an error if the element does not exist?
A) Using discard() B) Using pop() C) Using clear() D) Using remove()
- 13. Which method is used to delete a key-value pair associated with a specified key in a dictionary?
A) pop() B) remove() C) del() D) delete()
- 14. What does the in operator do in Python?
A) Checks if an element exists in a list B) Checks if a key exists in a dictionary C) Checks if a value is present in a set D) Checks if a substring is in a string
- 15. How can you find the index of the first occurrence of a specific element in a list?
A) Using index() B) Using search() C) Using locate() D) Using find()
- 16. Which method is used to merge the keys and values from one dictionary into another in Python?
A) merge() B) update() C) append() D) combine()
- 17. You can use a ______ to iterate over a list by manually managing an index variable.
A) While Loop B) Enumerate C) For Loop D) List Comprehension
- 18. A loop that is commonly used to iterate over the elements of a list.
A) Do While Loop B) While Loop C) Enumerate D) For Loop
- 19. What is the output of the following list comprehension? new_list = [x for x in range(10) if x % 2 == 0]
A) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] B) [1, 3, 5, 7, 9] C) [0, 2, 4, 6, 8] D) [0, 1, 2, 3, 4]
- 20. This is a built-in function that allows you to apply a specified function to each item in an iterable and returns an iterator of the results.
A) map function B) lambda function C) Enumerate function D) list function
- 21. How can you create a lambda function that multiplies two numbers?
A) multiply = lambda x, y: x + y B) multiply = lambda x, y: x / y C) multiply = lambda x, y: x * y D) multiply = lambda x, y: x - y
- 22. This a process of deliberately triggering an error condition within a program to indicate that something unexpected or erroneous has occurred.
A) With statement B) Cleaning up Exception C) Raising Exceptions D) Exception handling
- 23. What is the output of the following code snippet? my_list = [1, 2, 3, 4] removed_element = my_list.pop(2) print(removed_element)
A) 3 B) 1 C) 4 D) 2
- 24. This function can be used to create an iterator from elements of an iterable for which a function returns true.
A) filter() B) extend() C) index() D) get()
- 25. This is a way to extract individual elements from a list and assign them to variables in a single step
A) Looping over list B) sorted list C) List unpacking D) List
- 26. How can you check if a specific element exists in a collection in Python?
A) Using check() B) Using the in operator C) Using exists() D) Using verify()
- 27. Which method is used to add elements from another set to a set in Python?
A) combine() B) update() C) append() D) merge()
- 28. This is a collection of items that are ordered and changeable. It is one of the built-in data types that allows you to store a collection of values
A) Sorted list B) List C) Enumerate D) For Loop
- 29. How can you define a function that takes two parameters in Python?
A) def my_function(param1; param2) B) ef my_function(param1 - param2): C) def my_function(param1, param2): D) def my_function(param1 param2):
- 30. What keyword is used to iterate through a collection in Python?
A) while B) for C) loop D) iterate
- 31. Which keyword is used to specify a function to extract a comparison key from each element for custom sorting in Python?
A) extract B) compare C) key D) sort
- 32. What keyword is used to reverse the order of elements in a list in Python?
A) sort B) reverse C) invert D) backward
- 33. How to adds an element to a set
A) Using insert() B) Using append() C) Using extend() D) Using add()
- 34. A function that allows you to loop over both the elements and their indices in a list.
A) List Comprehension B) While Loop C) Enumerate D) For Loop
- 35. This is a block of reusable code that performs a specific task or set of tasks
A) Function B) Scope C) Arguments D) Parameters
- 36. A variables that is defined outside of any function have global scope and can be accessed from anywhere in the program
A) Scope B) Parameters C) Arguments D) Docstring
- 37. These are the values that the function expects to receive when it is called
A) Parameters B) Variables C) Scope D) Arguments
- 38. This refers to the values that are passed into a function when it is called.
A) Parameters B) Scope C) Variables D) Arguments
- 39. These are parameters in a function that have a default value specified in the function definition.
A) Arbitrary Arguments B) Positional Arguments C) Keyword Arguments D) Default Arguments
- 40. This allow you to pass a variable number of arguments to a function.
A) Default Arguments B) Arbitrary Arguments C) Keyword Arguments D) Positional Arguments
- 41. These are specified by using the parameter names followed by an equals sign = and the value to be passed.
A) Keyword Arguments B) Positional Arguments C) Default Arguments D) Arbitrary Arguments
- 42. This is iterating through each element of the list and performing some operation on each element
A) for loop B) sorting list C) Looping over list D) list unpacking
- 43. This provide a concise way to create a new list by performing an operation on each element of an existing list.
A) List unpacking B) List Comprehension C) sorted list D) Enumerate
- 44. A method to retrieve the value associated with a specific key.
A) extend() B) index() C) filter() D) get()
- 45. A function that returns a new sorted list from the elements of the original list. It does not modify the original list.
A) sorted() B) sort() C) index() D) filter()
- 46. Both sorted() and sort() functions that have a reverse parameter which, when set to True, sorts the list in descending order.
A) Reverse Sorting B) Sorting Strings C) Custom Sorting D) Sorting in Reverse Order
- 47. Both sorted() and sort() functions that accept a key parameter, which allows you to specify a function to extract a comparison key from each element.
A) Reverse Sorting B) Sorting Strings C) Custom Sorting D) lambda
- 48. Which escape sequence is used to represent a newline in a string?
A) \" B) \n C) \' D) \\
- 49. What is the out put of this code first = "Jann Erick" last = "Santos" full = f"{first} {last}" print(full)
A) Jann B) Erick Santos C) Jann Erick Santos D) Jann Santos
- 50. How would you capitalize the first letter of each word in the string 'course'?
A) print(course.title()) B) print(course.upper()) C) print(course.capitalize()) D) print(course.lower())
- 51. Which of the following variable names is invalid?
A) 1st_name B) _private_var C) courseName D) is_published
- 52. Which of the following is an example of a correctly defined integer variable in Python?
A) student_count = "1000" B) 1000 = student_count C) student_count = 1000 D) student-count = 1000
- 53. What is the correct way to define a string variable in Python?
A) course_name = Python Programming' B) course_name = "Python Programming" C) course_name = 'Python Programming' D) course_name = Python Programming
- 54. How would you print the first character of the string variable 'course'?
A) print(course[1]) B) print(course[first]) C) print(course[-1]) D) print(course[0])
- 55. Which Python function returns the absolute value of a number?
A) roundl() B) ciel() C) value() D) abs()
- 56. Which function from the math module returns the smallest integer greater than or equal to a given number?
A) math.sqrt() B) math.ceil() C) math.floor() D) math.pow()
- 57. What is the result of the following code? x = "10" y = int(x) + 1 print(y)
A) 10 B) 101 C) 11 D) 1
- 58. They cannot be a reserved keyword.They should be meaningful and descriptive names.They cannot start with a number like. They cannot contain space or hyphen
A) variable names B) String C) Arguments D) function
- 59. These are passed to a function in a specific order, and their values are assigned to the corresponding parameters defined in the function's signature
A) Positional Arguments B) Default Arguments C) Arbitrary Arguments D) Keyword Arguments
A) Di ako Papasa B) Papasa ako
- 61. In Python this refers to the process of managing errors that occur during the execution of a program
A) Handling Exception B) Exception Management C) Cleaning up Exception D) Exception handling
- 62. A function is defined using the def keyword, followed by the function name, a pair of parentheses (), and a colon :
A) Function Body B) Function Call C) Function Definition D) Function Reusability
- 63. This is a block of code that is indented beneath the def statement. It contains the instructions that the function will execute when called
A) Function Body B) Function Call C) Function Reusability D) Function Definition
- 64. This execute a function, you use its name followed by a pair of parentheses, optionally containing the arguments (values) that you want to pass to the function
A) Function Definition B) Function Call C) Function Reusability D) Function Body
- 65. This functions can be called multiple times from different parts of your program, allowing you to reuse the same code logic
A) Function Body B) Function Definition C) Function Reusability D) Function Call
- 66. This method sorts the list in-place, meaning it modifies the original list
A) filter() B) index() C) sort() D) sorted()
- 67. This is used to compare two values. It allows you to determine the relationship between these values
A) If Statement B) Conditional Statement C) Comparison Operator D) If-else Statement
- 68. This allow you to control the flow of execution in a program based on certain conditions.
A) If Statement B) Conditional Statement C) elif Statement D) If-else Statement
- 69. This statement is used to execute a block of code only if a specified condition is true. If the condition is false, the code block is skipped.
A) Nested if Statements B) If-else Statement C) elif Statement D) If Statement
- 70. This statement provides an alternative code block to execute if the condition is false.
A) If Statement B) Nested if Statements C) If-else Statement D) elif Statement
- 71. This statement allows you to check multiple conditions in a sequence. It is used when you have more than two possible outcomes.
A) If Statement B) If-else Statement C) Nested if Statements D) elif Statement
- 72. This statement allows you to place an if statement inside another if statement to handle more complex conditions.
A) elif Statement B) If Statement C) If-else Statement D) Nested if Statements
- 73. This allows you to write a concise one-line if-else statement.
A) Ternary Operator B) Conditional Statement C) Logical Operator D) Comparison Operator
- 74. These are used to perform operations on Boolean values (True or False).
A) Conditional Statement B) Comparison Operator C) Ternary Operator D) Logical Operator
- 75. This operator returns True if both of the operands are True. Otherwise, it returns False.
A) not B) or C) and D) equals
- 76. This operator returns True if at least one of the operands is True. If both operands are False, it returns False.
A) not B) or C) equals D) and
- 77. This operator is a unary operator that negates the value of a Boolean expression. It returns True if the expression is False, and False if the expression is True.
A) and B) equals C) or D) not
- 78. This can optionally return a value using the return statement.
A) Function Definition B) Return Value C) Function Call D) Function Reusability
- 79. What this sign "==" means?
A) Equal to B) Greater than or equal to C) Less than or equal to D) Not equal to
- 80. What this sign "!=" means?
A) Greater than or equal to B) Less than or equal to C) Equal to D) Not equal to
|