1. What is the output of the following code: print(type(5))?
ANS : (a) The output will be <class 'int'> because 5 is an integer.
2. Which of the following is a valid way to declare a list in Python?
ANS : (c) Both list = [] and list = list() are valid ways to declare a list in Python.
3. What is the output of the following code: print(2 ** 3)?
ANS : (b) The output will be 8 because 2 ** 3 means 2 raised to the power of 3.
4. Which of the following is used to define a function in Python?
ANS : (b) The correct way to define a function in Python is def myFunction():.
5. What is the output of the following code: print("Hello" + " World")?
ANS : (b) The output will be HelloWorld because there is no space between the two strings.
6. Which of the following is the correct way to create a dictionary in Python?
ANS : (c) Both dict = {} and dict = dict() are valid ways to create a dictionary in Python.
7. What is the output of the following code: print(10 // 3)?
ANS : (b) The output will be 3 because // is the floor division operator in Python.
8. Which of the following is used to handle exceptions in Python?
ANS : (a) The try-except block is used to handle exceptions in Python.
9. What is the output of the following code: print(len("Hello"))?
ANS : (a) The output will be 5 because the length of the string "Hello" is 5.
10. Which of the following is the correct way to import a module in Python?
ANS : (a) The correct way to import a module in Python is import module_name.
11. What is the output of the following code: print(3 * 'A')?
ANS : (a) The output will be AAA because multiplying a string by an integer repeats the string.
12. Which of the following is used to read input from the user in Python?
ANS : (a) The correct function to read input from the user in Python is input().
13. What is the output of the following code: print(2 + 3 * 4)?
ANS : (b) The output will be 14 because of the order of operations (multiplication before addition).
14. Which of the following is a mutable data type in Python?
ANS : (a) A List is a mutable data type in Python, meaning it can be changed after creation.
15. What is the output of the following code: print("Python"[0])?
ANS : (a) The output will be P because it accesses the first character of the string "Python".
16. Which of the following is the correct way to create a class in Python?
ANS : (a) The correct way to create a class in Python is class MyClass:.
17. What is the output of the following code: print(1, 2, 3, sep='-')?
ANS : (a) The output will be 1-2-3 because the sep parameter specifies the separator.
18. Which of the following is used to create a virtual environment in Python?
ANS : (c) Both virtualenv and venv can be used to create a virtual environment in Python.
19. What is the output of the following code: print([1, 2, 3] + [4, 5, 6])?
ANS : (a) The output will be [1, 2, 3, 4, 5, 6] because the + operator concatenates two lists.
20. Which of the following is the correct way to handle exceptions in Python?
ANS : (a) The correct way to handle exceptions in Python is using the try-except block.
21. What is the output of: len("Python")?
ANS : (b) The len() function returns the number of characters, which is 6 in this case.
22. Which of the following is a mutable data type in Python?
ANS : (b) Lists are mutable, meaning they can be changed after creation.
23. What is the output of: type({})?
ANS : (c) An empty pair of curly braces {} represents a dictionary.
24. What does the range(5) function return?
ANS : (b) range(5) generates numbers from 0 to 4.
25. What is the keyword used to define a function in Python?
ANS : (b) The def keyword is used to define functions in Python.
26. Which method is used to convert a string into lowercase in Python?
ANS : (a) The lower() method converts a string into lowercase.
27. What is the output of: bool(0)?
ANS : (b) In Python, bool(0) evaluates to False.
28. Which of the following is not a keyword in Python?
ANS : (b) eval is a built-in function, not a keyword.
29. Which of the following is used to comment a single line in Python?
ANS : (b) Python uses the # symbol for single-line comments.
30. What does the strip() method do in Python?
ANS : (c) The strip() method removes whitespace from both ends of a string.
31. What will be the result of 3 ** 2 in Python?
ANS : (b) ** is the exponentiation operator. So, 3 ** 2 = 9.
32. Which of the following data types is not ordered?
ANS : (c) Sets are unordered collections.
33. What does the pop() method do in a list?
ANS : (b) The pop() method removes and returns the last item in a list.
34. What keyword is used to create a class in Python?
ANS : (c) The class keyword is used to define a class in Python.
35. Which method adds an element at the end of a list?
ANS : (b) The append() method adds an element at the end of a list.
36. What is the default return value of a function that does not return anything?
ANS : (c) If a function does not explicitly return a value, it returns None by default.
37. Which function converts a string to an integer in Python?
ANS : (a) The int() function converts a string or number to an integer.
38. What symbol is used for floor division in Python?
ANS : (b) // is used for floor division in Python.
39. Which keyword is used to begin a loop in Python?
ANS : (c) for is the keyword used to begin a loop in Python.
40. What is the output of 10 % 3?
ANS : (b) The % operator returns the remainder, which is 1 in this case.
41. Which of these is not a core data type in Python?
ANS : (c) Class is not a core data type, it's a structure to define user-defined types.
42. What does the len() function do?
ANS : (c) len() returns the number of items in an object.
43. Which function is used to get input from the user?
ANS : (b) input() is used to take input from the user in Python.
44. What is the output of bool(0)?
ANS : (b) bool(0) returns False because 0 is considered False in Python.
45. Which of the following is used to define a function in Python?
ANS : (a) The def keyword is used to define a function.
46. What will be the output of type([])?
ANS : (c) [] denotes a list in Python, so type([]) returns <class 'list'>.
47. Which loop is guaranteed to run at least once?
ANS : (c) Python does not have a do-while loop, but in general programming, a do-while loop runs at least once.
48. What will be the result of 'a' + 'b'?
ANS : (a) The + operator concatenates strings, so 'a' + 'b' = 'ab'.
49. Which method is used to convert a string to lowercase?
ANS : (a) lower() is used to convert a string to all lowercase letters.
50. Which keyword is used to import a module in Python?
ANS : (c) The import keyword is used to include external modules in Python.