Top 100+ Python Questions and Answers PDF
1. What is Python?
a) A high-level programming language
b) A low-level programming language
c) An assembly language
d) A markup language
2. Which of the following is NOT a core data type in Python?
a) List
b) Dictionary
c) Table
d) Tuple
3. Which keyword is used for defining a function in Python?
a) def
b) function
c) define
d) func
4. What is the output of 2 + 3 * 5
in Python?
a) 25
b) 17
c) 25.0
d) 5
5. Which symbol is used for comments in Python?
a) //
b) #
c) //
d) ”’
6. What will print("Hello" + "World")
output?
a) Hello World
b) HelloWorld
c) Hello + World
d) Error
7. What is the output of len("Python")
?
a) 5
b) 6
c) 7
d) Error
8. Which method removes an item from a list in Python?
a) delete()
b) remove()
c) pop()
d) discard()
9. Which operator is used for exponentiation in Python?
a) **
b) ^
c) //
d) %
10. What is the output of 2 * 3 ** 2
?
a) 18
b) 12
c) 27
d) 9
11. How do you start a while loop in Python?
a) while
b) loop
c) for
d) do
12. Which method is used to convert a string to lowercase in Python?
a) to lower()
b) lower()
c) lowercase()
d) case_lower()
13. What does the range()
function in Python return?
a) A list of numbers
b) A tuple of numbers
c) A generator object
d) A dictionary of numbers
14. How do you round 3.14 to the nearest integer in Python?
a) round(3.14)
b) round(3.14, 0)
c) round(3.14, 1)
d) round(3.14, 2)
15. Which of the following data structures is mutable in Python?
a) Tuple
b) List
c) String
d) Set
16. What is the output of print("Hello" * 3)
?
a) HelloHelloHello
b) 9
c) Error
d) Hello3
17. How do you check the length of a list in Python?
a) length()
b) len()
c) size()
d) count()
18. Which statement is used for exiting a loop in Python?
a) break
b) stop
c) exit
d) end
19. What will print(5 == 5)
output?
a) True
b) False
c) 5
d) Error
20. Which of the following is NOT a valid variable name in Python?
a) my_variable
b) 1_variable
c) variable_1
d) _variable
21. How do you define a dictionary in Python?
a) {key: value}
b) [key, value]
c) {key=value}
d) (key, value)
22. Which method is used to sort a list in Python?
a) sort()
b) sorted()
c) sort_list()
d) order()
23. What is the output of print("Python"[1:4])
?
a) Pyt
b) yth
c) thon
d) Pyth
24. How do you check if a key exists in a dictionary?
a) key_exists()
b) has_key()
c) in
d) exists()
25. What will print(10 / 3)
output?
a) 3.3333
b) 3
c) 3.0
d) Error
26. Which function is used to take user input in Python?
a) input()
b) read()
c) get_input()
d) user_input()
27. What does the pass
Does statement do in Python?
a) Executes nothing
b) Continues to the next iteration of a loop
c) Breaks out of a loop
d) Raises an error
28. How do you concatenate two lists in Python?
a) list1 + list2
b) concat(list1, list2)
c) join(list1, list2)
d) extend(list1, list2)
29. What is the output of print("Hello"[::-1])
?
a) Hello
b) olleH
c) ello
d) H
30. Which module in Python is used for regular expressions?
a) regex
b) re
c) regexpy
d) reg
31. What is the output of bool(0)
?
a) True
b) False
c) Error
d) 0
32. How do you remove all elements from a list in Python?
a) clear()
b) pop()
c) remove()
d) del
33. Which of the following is the correct way to create a tuple in Python?
a) (1, 2, 3)
b) {1, 2, 3}
c) [1, 2, 3]
d) “1, 2, 3”
34. What is the output of print("Python"[2:4])
?
a) Pyt
b) th
c) Py
d) thon
35. How do you check if a value exists in a list in Python?
a) value_exists()
b) has_value()
c) in
d) exists()
36. Which method is used to append an element to a list in Python?
a) add()
b) insert()
c) append()
d) extend()
37. What is the output of print(10 % 3)
?
a) 3
b) 1
c) 3.3333
d) Error
38. What does the ord()
function do in Python?
a) Returns the ASCII value of a character
b) Converts a character to lowercase
c) Converts a character to uppercase
d) Returns the Unicode value of a character
39. How do you check the type of a variable in Python?
a) typeOf()
b) typeof()
c) type()
d) varType()
40. What will print("Python"[3])
output?
a) P
b) y
c) t
d) h
41. Which operator is used for floor division in Python?
a) //
b) /
c) %
d) **
42. What is the output of print("Python"[::-1])
?
a) Python
b) nohtyP
c) pythoN
d) Error
43. How do you check if a value exists in a dictionary in Python?
a) value_exists()
b) has_value()
c) in
d) exists()
44. What is the output of print(5 != 5)
?
a) True
b) False
c) 5
d) Error
45. How do you create a set in Python?
a) {1, 2, 3}
b) [1, 2, 3]
c) (1, 2, 3)
d) “1, 2, 3”
46. Which method checks if a string starts with a specific substring in Python?
a) starts_with()
b) starts with()
c) begins_with()
d) begins with()
47. What is the output of print("Python"[2:])
?
a) Py
b) th
c) thon
d) None
48. How do you remove the last element from a list in Python?
a) pop()
b) remove()
c) del
d) clear()
49. Which method is used to combine list elements into a string in Python?
a) join()
b) concat()
c) merge()
d) combine()
50. What will print(2 ** 3)
output?
a) 6
b) 9
c) 8
d) 5
51. How do you check if a string contains only digits in Python?
a) isdigit()
b) only_digits()
c) has_digits()
d) contains_digits()
52. What is the output of print(10 < 5)
?
a) True
b) False
c) 10
d) 5
53. Which method is used to reverse a list in Python?
a) reverse()
b) reversed()
c) reverse_list()
d) flip()
54. What will print(3 + 2 * 4 / 2)
output?
a) 5
b) 10
c) 7
d) 9
55. How do you convert an integer to a string in Python?
a) str()
b) int_to_str()
c) to_string()
d) convert()
56. What is the output of print("Python"[1])
?
a) P
b) y
c) t
d) h
57. Which method is used to find the index of an element in a list in Python?
a) index()
b) find()
c) search()
d) locate()
58. What is the output of print(10 == 5)
?
a) True
b) False
c) 10
d) 5
59. How do you create a copy of a list in Python?
a) copy()
b) clone()
c) duplicate()
d) replicate()
60. What is the output of print(3 != 3)
?
a) True
b) False
c) 3
d) Error
61. What will be the output of the following Python code? x = 123 for i in x: print(i)
a) 1 2 3
b) 123
c) error
d) none of the mentioned