top of page

​

 

50 MCQ Questions

 

1. Which of the following is a valid variable name in Python?

 

a) 2ndValue

b) first-value

c) first_value

d) first value

 

2. What will be the output of the following code?

 

x = 10

y = 3

print(x // y)

 

a) 3.3333

b) 3

c) 3.0

d) Error

 

3. Which operator is used to check if two values are not equal in Python?

 

a) =!

b) ==

c) !=

d) <>

 

4. In Python, what is the result of 3 * 2 ** 2?

 

a) 12

b) 16

c) 3

d) 6

 

5. Which data type is best suited for a value like "Hello World" in Python?

 

a) int

b) float

c) str

d) bool

 

6. What is the output of the following code?

 

num = 5

num_str = "5"

print(num + int(num_str))

 

a) “55”

b) 10

c) Error

d) 0

 

7. Which statement correctly checks if a is greater than b?

 

a) if a > b:

b) if (a) > (b):

c) if a >> b:

d) if a => b:

 

8. In Python, which keyword is used to define a function?

 

a) function

b) func

c) def

d) define

 

9. Which of the following is not a valid Python data type?

 

a) list

b) tuple

c) dictionary

d) arraylist

 

10. What does the following code snippet do?

 

for i in range(5):

    print(i)

 

a) Prints 0 1 2 3 4

b) Prints 1 2 3 4 5

c) Prints 5

d) Error

 

11. How do you create a comment in Python?

 

a) */ comment */

b) // comment

c) # comment

d) <!-- comment -->

 

12. Which of the following is the correct way to open a file called "data.txt" for reading in Python?

 

a) open("data.txt", "w")

b) open("data.txt", "wb")

c) open("data.txt")

d) open("data.txt", "r")

 

13. What will be the output of this code segment?

 

x = 10

if x < 5:

    print("Less than 5")

elif x < 15:

    print("Less than 15")

else:

    print("Greater than or equal to 15")

 

a) Less than 5

b) Less than 15

c) Greater than or equal to 15

d) Error

 

14. If a Python list is defined as my_list = [1, 2, 3, 4], what is my_list[2]?

 

a) 2

b) 3

c) 1

d) 4

 

15. Which function in Python can be used to find the length of a list named my_list?

 

a) length(my_list)

b) size(my_list)

c) len(my_list)

d) my_list.len()

 

16. What will be the output of:

 

string = "abcdef"

print(string[1:4])

 

a) “bcd”

b) “abc”

c) “bcde”

d) “cde”

 

17. Which loop structure would you use if you want to repeat an action while a certain condition remains True?

 

a) for loop

b) while loop

c) do-while loop

d) foreach loop

 

18. What is the result of this expression: 5 + 2 * 3 in Python?

 

a) 21

b) 11

c) 13

d) 17

 

19. In Python, how can you add an element x to the end of a list my_list?

 

a) my_list.push(x)

b) my_list.add(x)

c) my_list.append(x)

d) my_list.extend(x)

 

20. Which of the following is a Boolean operator in Python?

 

a) +

b) and

c) =

d) **

 

21. If my_list = [5, 10, 15, 20], which of these retrieves a slice of [10, 15]?

 

a) my_list[1:3]

b) my_list[2:4]

c) my_list[0:2]

d) my_list[-2:]

 

22. What does print(type(3.14)) display in Python?

 

a) <class 'str'>

b) <class 'float'>

c) <class 'int'>

d) <class 'double'>

 

23. Choose the correct syntax for a multi-line comment in Python:

 

a) // This is a multiline comment //

b) /* This is a multiline comment */

c) """ This is a multiline comment """

d) <-- This is a multiline comment -->

 

24. What will the following code print?

 

x = 2

y = 10

x *= y

print(x)

 

a) 2

b) 10

c) 5

d) 20

 

25. Which function converts a string to an integer in Python?

 

a) str()

b) int()

c) float()

d) string()

 

26. What is the result of the following code?

 

count = 0

for i in range(3, 6):

    count += i

print(count)

 

a) 3

b) 12

c) 0

d) 6

 

27. What is not a valid way to start a Python file name?

 

a) myProgram.py

b) _testFile.py

c) 5example.py

d) calc_file.py

 

28. In Python, strings are:

 

a) Mutable (they can be changed after creation)

b) Immutable (they cannot be changed once created)

c) Sometimes mutable, sometimes not

d) None of the above

 

29. while True: in Python means:

 

a) The loop runs as long as the condition is not met

b) The loop will never run

c) The loop runs indefinitely until a break is encountered

d) It is invalid syntax

 

30. What does the break statement do?

 

a) Skips the current iteration and continues with the next

b) Terminates the entire loop immediately

c) Moves the pointer to the next line of code

d) Exits the current function

 

31. If my_tuple = (10, 20, 30), what happens if you execute my_tuple[1] = 40?

 

a) my_tuple becomes (10, 40, 30)

b) Error: Tuples are immutable

c) No change, Python ignores the assignment

d) The value at index 1 is replaced with 40, no error

 

32. In a function definition, which keyword is used to specify default values for parameters?

 

a) default

b) return

c) =

d) pass

 

33. Which of these is the correct syntax to define a dictionary in Python?

 

a) dict = [ "apple": 1, "banana": 2 ]

b) dict = { "apple" = 1, "banana" = 2 }

c) dict = { "apple": 1, "banana": 2 }

d) dict = ( "apple"->1, "banana"->2 )

 

34. When you use the open("file.txt", "r") mode, you are:

 

a) Reading a file in binary mode

b) Writing to a file in text mode

c) Reading a file in text mode

d) Appending to a file in text mode

 

35. Which of the following is not a Python keyword?

 

a) with

b) lambda

c) pass

d) then

 

36. Select the correct syntax to define a function that takes no parameters and prints “Hello”.

 

a)

 

function hello():

    print("Hello")

 

b)

 

def hello():

    print("Hello")

 

c)

 

def hello:

    print("Hello")

 

d)

 

function hello[]:

    print("Hello")

 

37. If you want to write text to a file without overwriting existing content, which mode should you use?

 

a) "w"

b) "r"

c) "a"

d) "wb"

 

38. Which method removes the last item from a list and returns it?

 

a) pop()

b) remove()

c) delete()

d) discard()

 

39. In Python, range(2, 10, 2) generates which sequence of numbers?

 

a) 2, 10

b) 2, 4, 6, 8

c) 2, 4, 6, 8, 10

d) 2, 3, 4, 5, 6, 7, 8, 9

 

40. Which of these statements is true about Python?

 

a) Indentation is optional

b) Indentation is required to define blocks of code

c) Curly braces {} are used to define code blocks

d) Semicolons must end every line

 

41. What is the output of the following code?

 

def sum_nums(a, b=5):

    return a + b

 

print(sum_nums(10))

 

a) 15

b) 5

c) Error: missing parameter

d) 10

 

42. In Python, what does str(123) return?

 

a) 123 (integer)

b) '123' (string)

c) 1.23 (float)

d) Error

 

43. Which of the following correctly checks membership in a list names?

 

a) if "Alice" in names:

b) if ("Alice") => names:

c) if names.contains("Alice"):

d) if "Alice" is names:

 

44. What is the correct way to import the entire math module?

 

a) import math

b) from math import sqrt

c) using math

d) #include math

 

45. Which of these is not a valid comparison operator in Python?

 

a) >=

b) <=

c) ==

d) =@

 

46. In Python, what does len("Hello") return?

 

a) 4

b) 5

c) 6

d) "Hello".length()

 

47. Consider the code:

 

my_list = ["apple", "banana", "cherry"]

my_list.insert(1, "orange")

print(my_list)

 

What is the output?

a) ["apple", "banana", "cherry", "orange"]

b) ["apple", "orange", "banana", "cherry"]

c) ["orange", "apple", "banana", "cherry"]

d) ["apple", "banana", "orange", "cherry"]

 

48. What is the output of:

 

for i in range(3):

    print("Hi")

 

a) No output

b) “Hi” once

c) “Hi” three times

d) Error in syntax

 

49. If you wanted to exit a loop early based on a condition, which statement would you use?

 

a) continue

b) stop

c) exit

d) break

 

50. How do you convert an integer x to a string in Python?

 

a) x.convertToString()

b) string(x)

c) str(x)

d) toString(x)

 

Answers

1. c

2. b

3. c

4. a

5. c

6. b

7. a

8. c

9. d

10. a

11. c

12. d

13. b

14. b

15. c

16. a

17. b

18. b (Order of operations: 2 * 3 = 6, then 5 + 6 = 11)

19. c

20. b

21. a

22. b

23. c

24. d

25. b

26. b (Range(3, 6) = 3+4+5 = 12)

27. c (File names generally cannot start with a digit when used as modules; also not recommended practice)

28. b

29. c

30. b

31. b

32. c

33. c

34. c

35. d

36. b

37. c

38. a

39. b

40. b

41. a

42. b

43. a

44. a

45. d

46. b

47. b (Insert at index 1 puts “orange” between “apple” and “banana”)

48. c

49. d

50. c

 

​

bottom of page