1. What does the 'def' keyword do in Python?
A) It defines a new variable
B) It defines a new function
C) It creates a class
D) It imports a module
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. Which of the following is used to create a list in Python?
A) []
B) ()
C) {}
D) <>
Show Explanation
4. How do you access the value associated with the key 'name' in a dictionary?
A) dict.name
B) dict['name']
C) dict{name}
D) dict.get('name')
Show Explanation
5. What is the output of `print(2 ** 3)` in Python?
A) 5
B) 6
C) 8
D) 9
Show Explanation
6. What will be the result of `len("Hello World")`?
A) 10
B) 11
C) 12
D) 13
Show Explanation
7. What is the purpose of the 'pass' statement in Python?
A) To terminate a loop
B) To skip to the next iteration
C) To do nothing
D) To define a function
Show Explanation
8. What will be the output of the following code? `print(type([]))`
A) <class 'list'>
B) <class 'dict'>
C) <class 'tuple'>
D) <class 'set'>
Show Explanation
9. How do you check if a key 'age' exists in a dictionary?
A) 'age' in dict
B) dict.has_key('age')
C) dict.contains('age')
D) 'age' in dict.keys()
Show Explanation
10. What will be the output of `sorted([3, 1, 2])`?
A) [1, 2, 3]
B) [3, 2, 1]
C) [2, 1, 3]
D) [1, 3, 2]
Show Explanation
11. What is the purpose of a for loop in Python?
A) To iterate indefinitely
B) To define a function
C) To iterate over a sequence
D) To create a variable
Show Explanation
12. What does the 'continue' statement do in a loop?
A) Ends the loop
B) Skips to the next iteration
C) Repeats the loop
D) Stops the program
Show Explanation
13. What is the purpose of the 'elif' statement in Python?
A) To terminate a loop
B) To check another condition
C) To define a function
D) To create a variable
Show Explanation
14. How do you include a module in Python?
A) include module_name
B) require module_name
C) load module_name
D) import module_name
Show Explanation
15. What is the purpose of a while loop in Python?
A) To execute code as long as a condition is true
B) To define a function
C) To create a variable
D) To iterate over a list
Show Explanation
16. What does the 'break' statement do in a loop?
A) Ends the program
B) Skips the current iteration
C) Exits the loop
D) Repeats the loop
Show Explanation
17. What does the 'map()' function do in Python?
A) Filters a list
B) Applies a function to all items in an iterable
C) Creates a new list
D) Sorts a list
Show Explanation
18. What does the 'filter()' function do in Python?
A) Applies a function to all items
B) Combines two lists
C) Filters a list based on a condition
D) Sorts a list
Show Explanation
19. What does the 'join()' method do in Python?
A) Splits a string into a list
B) Joins elements of an iterable into a single string
C) Reverses a string
D) Converts a string to lowercase
Show Explanation
20. What does the 'len()' function do in Python?
A) Returns the first item
B) Returns the last item
C) Checks if an item exists
D) Returns the number of items in an object
Show Explanation