1. What is the output of print(2**3)
?
a) 6
b) 8
c) 9
d) 5
✔️ Answer: b) 8
2. What data type is the object below? L = [1, 23, 'hello', 1]
a) Tuple
b) Dictionary
c) List
d) Set
✔️ Answer: c) List
3. Which keyword is used to define a function in Python?
a) func
b) define
c) def
d) function
✔️ Answer: c) def
4. What does len([1, 2, 3, 4])
return?
a) 4
b) 3
c) 2
d) 5
✔️ Answer: a) 4
5. What is the correct file extension for Python files?
a) .pyth
b) .pt
c) .py
d) .p
✔️ Answer: c) .py
6. What is the output of print(type("5"))
?
a) int
b) float
c) str
d) char
✔️ Answer: c) str
7. Which of the following is a valid variable name in Python?
a) 1var
b) _var
c) var-1
d) for
✔️ Answer: b) _var
8. What is the output of bool([])
?
a) True
b) False
✔️ Answer: b) False
9. What does //
operator do in Python?
a) Modulus
b) Float division
c) Floor division
d) Power
✔️ Answer: c) Floor division
10. What does the pass
statement do?
a) Skips iteration
b) Ends loop
c) Does nothing
d) Returns value
✔️ Answer: c) Does nothing
11. What is the output of 'Hello' + str(5)
?
a) Hello5
b) Error
c) Hello 5
d) 5Hello
✔️ Answer: a) Hello5
12. How do you insert comments in Python?
a) //
b) /* */
c)
d) #
✔️ Answer: d) #
13. What is the output of print("Hello"[1])
?
a) H
b) e
c) l
d) o
✔️ Answer: b) e
14. Which method can be used to remove whitespace from both ends of a string?
a) strip()
b) trim()
c) clean()
d) remove()
✔️ Answer: a) strip()
15. What is the output of print(10 % 3)
?
a) 3
b) 0
c) 1
d) 10
✔️ Answer: c) 1
16. Which loop is used to iterate over a sequence?
a) for
b) while
c) loop
d) repeat
✔️ Answer: a) for
17. What is the output of 3 * 'A'
?
a) AAA
b) 3A
c) A3
d) Error
✔️ Answer: a) AAA
18. What is the output of type(3.14)
?
a) int
b) float
c) double
d) decimal
✔️ Answer: b) float
19. Which function returns the length of a string?
a) length()
b) size()
c) len()
d) count()
✔️ Answer: c) len()
20. Which of the following is an immutable data type?
a) list
b) dict
c) set
d) tuple
✔️ Answer: d) tuple
21. How do you define a dictionary in Python?
a) {}
b) []
c) ()
d) {key: value}
✔️ Answer: d) {key: value}
22. Which method adds an item to the end of a list?
a) insert()
b) add()
c) append()
d) extend()
✔️ Answer: c) append()
23. Which keyword is used for exception handling?
a) catch
b) handle
c) try
d) detect
✔️ Answer: c) try
24. Which module is used for regular expressions?
a) regex
b) re
c) rexp
d) exp
✔️ Answer: b) re
25. Which of these is a correct if
statement?
a) if a = b:
b) if a == b:
c) if (a == b)
d) if a === b:
✔️ Answer: b) if a == b:
26. What does range(5)
produce?
a) 0–5
b) 1–5
c) 0–4
d) 1–4
✔️ Answer: c) 0–4
27. What is the output of print(10 != 5)
?
a) True
b) False
✔️ Answer: a) True
28. What will my_list = [1, 2, 3]; print(my_list[-1])
output?
a) 1
b) 2
c) 3
d) Error
✔️ Answer: c) 3
29. Which of these is a Python tuple?
a) [1, 2]
b) {1, 2}
c) (1, 2)
d) <1, 2>
✔️ Answer: c) (1, 2)
30. What does open('file.txt', 'r')
do?
a) Opens file for writing
b) Opens file for reading
c) Opens file for appending
d) Deletes the file
✔️ Answer: b) Opens file for reading
31. Which function is used to convert a string to lowercase?
a) lower()
b) down()
c) lowercase()
d) strlower()
✔️ Answer: a) lower()
32. What does is
compare?
a) Values
b) Memory location
c) Types
d) Length
✔️ Answer: b) Memory location
33. What does the break
keyword do in a loop?
a) Skips iteration
b) Exits loop
c) Restarts loop
d) Ends program
✔️ Answer: b) Exits loop
34. Which function returns the absolute value?
a) abs()
b) fabs()
c) math.abs()
d) absolute()
✔️ Answer: a) abs()
35. Which operator is used for exponentiation?
a) ^
b) **
c) %
d) //
✔️ Answer: b) **
36. How is a block of code defined in Python?
a) Using { }
b) Using indentation
c) Using BEGIN and END
d) Using ()
✔️ Answer: b) Using indentation
37. What is None
in Python?
a) Boolean
b) Integer
c) Null object
d) Empty string
✔️ Answer: c) Null object
38. What is the result of 'abc'.upper()
?
a) abc
b) ABC
c) Abc
d) error
✔️ Answer: b) ABC
39. Which module supports working with JSON data?
a) json
b) csv
c) file
d) object
✔️ Answer: a) json
40. What does list(set([1, 2, 2, 3]))
return?
a) [1, 2, 2, 3]
b) [1, 2, 3]
c) [2, 2]
d) Error
✔️ Answer: b) [1, 2, 3]
41. Python is a…?
a) Compiled language
b) Interpreted language
c) Both
d) None
✔️ Answer: b) Interpreted language
42. Which of the following is not a keyword in Python?
a) finally
b) eval
c) assert
d) nonlocal
✔️ Answer: b) eval
43. What is the output of bool("False")
?
a) False
b) True
c) Error
d) None
✔️ Answer: b) True
44. What is the output of print([1, 2] + [3, 4])
?
a) [1, 2, 3, 4]
b) [4, 6]
c) [1, 2][3, 4]
d) Error
✔️ Answer: a) [1, 2, 3, 4]
45. What is slicing in Python?
a) Breaking a string
b) Dividing lists
c) Extracting a portion
d) Splitting strings
✔️ Answer: c) Extracting a portion
46. Which keyword is used to create a class in Python?
a) struct
b) class
c) object
d) type
✔️ Answer: b) class
47. Python supports…
a) Object-oriented programming
b) Functional programming
c) Procedural programming
d) All of the above
✔️ Answer: d) All of the above
48. input()
function returns data as:
a) int
b) float
c) str
d) bool
✔️ Answer: c) str
49. To read a CSV file, which module is commonly used?
a) file
b) os
c) csv
d) reader
✔️ Answer: c) csv
50. Python was created by:
a) Guido van Rossum
b) Dennis Ritchie
c) Bjarne Stroustrup
d) James Gosling
✔️ Answer: a) Guido van Rossum
Leave a Reply