1. How do you import a module in Python?
A) import module_name
B) include module_name
C) require module_name
D) load module_name
Show Explanation
2. What is the purpose of the __init__() method in a class?
A) To define a function
B) To create a variable
C) To delete an object
D) To initialize an object's attributes
Show Explanation
3. What is a lambda function in Python?
A) A function that can take multiple expressions
B) An anonymous function defined with the lambda keyword
C) A function defined without a return statement
D) A function with a fixed number of arguments
Show Explanation
4. What does the 'in' operator do in Python?
A) It concatenates two strings
B) It checks if two variables are equal
C) It checks for membership in a collection
D) It performs a mathematical operation
Show Explanation
5. What does the filter() function do in Python?
A) It filters elements from an iterable based on a function
B) It sorts the elements of an iterable
C) It modifies the original iterable
D) It counts the number of elements in an iterable
Show Explanation
6. What does the range() function do in Python?
A) It creates a list of numbers
B) It generates a sequence of numbers
C) It checks if a number is in a list
D) It returns the length of a list
Show Explanation
7. What does the map() function do in Python?
A) It applies a function to all items in an iterable
B) It creates a new list
C) It filters out certain items from a list
D) It converts all items in a list to strings
Show Explanation
8. What does the .upper() method do in Python?
A) It converts a string to lowercase
B) It removes whitespace from a string
C) It converts all characters to uppercase
D) It counts the number of characters in a string
Show Explanation
9. What does the .strip() method do in Python?
A) It removes all whitespace from a string
B) It converts a string to lowercase
C) It counts the number of spaces in a string
D) It removes leading and trailing whitespace
Show Explanation
10. What does the append() method do in a list?
A) It removes an item from a list
B) It adds an item to the end of a list
C) It sorts the items in a list
D) It creates a copy of the list
Show Explanation
11. What is the purpose of the break statement in Python?
A) To pause execution of the program
B) To skip the current iteration of a loop
C) To exit a loop
D) To restart a loop
Show Explanation
12. What is a module in Python?
A) A built-in function
B) A type of loop
C) A method of data structure
D) A file containing Python code
Show Explanation
13. What does the return statement do in a function?
A) Exits a function and returns a value
B) Defines a function
C) Starts a loop
D) Raises an exception
Show Explanation
14. What does the list() function do in Python?
A) It converts a string to a list
B) It sorts a list
C) It creates a list from an iterable
D) It removes duplicates from a list
Show Explanation
15. What is the purpose of try and except blocks in Python?
A) To define functions
B) To handle exceptions and errors
C) To create loops
D) To define classes
Show Explanation
16. What does the len() function do in Python?
A) It creates a new list
B) It checks the type of an object
C) It removes an item from a list
D) It returns the number of items in an object
Show Explanation
17. What is a dictionary in Python?
A) A sequence of characters
B) A list of numbers
C) A collection of key-value pairs
D) A function that returns multiple values
Show Explanation
18. What does the continue statement do in a loop?
A) It skips the current iteration
B) It exits the loop
C) It restarts the loop
D) It pauses execution of the loop
Show Explanation
19. What does the input() function do in Python?
A) It outputs data to the console
B) It captures user input
C) It converts input to an integer
D) It stores data in a file
Show Explanation
20. What does the import statement do in Python?
A) It exports a module
B) It creates a new module
C) It defines a new function
D) It includes a module in the code
Show Explanation