0% found this document useful (0 votes)
2 views11 pages

Python Mcqs

The document contains a list of 70 multiple-choice questions (MCQs) related to Python programming concepts, including data types, operators, loops, and data structures. Each question is followed by four answer options, with the correct answer indicated. The content is designed to test knowledge of Python fundamentals.

Uploaded by

zeeshangulkhalid
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views11 pages

Python Mcqs

The document contains a list of 70 multiple-choice questions (MCQs) related to Python programming concepts, including data types, operators, loops, and data structures. Each question is followed by four answer options, with the correct answer indicated. The content is designed to test knowledge of Python fundamentals.

Uploaded by

zeeshangulkhalid
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

​Here are all 70 MCQs in plain text format for copying:

1. Python is best described as:


A) Statically typed
B) Dynamically typed
C) Strongly compiled
D) Untyped
Answer: B

2. Which of the following is NOT a valid variable type mentioned in the slides?
A) int
B) float
C) bool
D) array
Answer: D

3. By convention, variable names typically start with:


A) Uppercase letters
B) Numbers
C) Lowercase letters
D) Underscores only
Answer: C

4. Which function is used to check the data type of a variable?


A) print()
B) type()
C) check()
D) typeof()
Answer: B

5. The process of converting a variable from one type to another is called:


A) Mapping
B) Casting
C) Binding
D) Wrapping
Answer: B

6. Which operator is used for exponentiation (power) in Python?


A) ^
B) **
C) //
D) %
Answer: B

7. x += 1 is shorthand for:
A) x = 1
B) x = x + 1
C) x = x - 1
D) x = x * 1
Answer: B

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


A) and
B) plus
C) equals
D) divide
Answer: A

9. Which symbol represents "greater than or equal to"?


A) =>
B) >=
C) =<
D) >>
Answer: B

10. Which operator checks equality between two values?


A) =
B) ==
C) !=
D) <>
Answer: B

11. A dictionary in Python stores data as:


A) Ordered lists
B) Key-value pairs
C) Tuples only
D) Single values
Answer: B

12. In Python indexing, the first element of a list has index:


A) 1
B) -1
C) 0
D) None
Answer: C

13. To access the last element of a list using negative indexing, you would use:
A) [0]
B) [-1]
C) [1]
D) [last]
Answer: B

14. Which container type is immutable?


A) List
B) Dictionary
C) Tuple
D) Set
Answer: C

15. Tuples are denoted using:


A) []
B) {}
C) ()
D) <>
Answer: C

16. Lists are denoted using:


A) ()
B) []
C) {}
D) //
Answer: B

17. Which is a key difference between lists and tuples?


A) Lists are immutable, tuples are mutable
B) Lists are mutable, tuples are immutable
C) Both are immutable
D) Both are mutable
Answer: B

18. Which function replaces an element in a list by index assignment?


A) append()
B) insert()
C) Direct index assignment (e.g., list[1] = value)
D) del
Answer: C

19. Which function adds an element at a specific position without overwriting existing elements?
A) append()
B) insert()
C) remove()
D) pop()
Answer: B
20. Which function adds an element to the END of a list?
A) insert()
B) append()
C) add()
D) extend_end()
Answer: B

21. If a list has multiple elements with the same value and you use remove(value), how many are removed?
A) All occurrences
B) None
C) Only the first occurrence
D) Only the last occurrence
Answer: C

22. Which keyword/function removes an element from a list by its index?


A) remove()
B) del
C) pop_index()
D) clear()
Answer: B

23. A for loop is primarily used to:


A) Define a function
B) Iterate over elements in a sequence
C) Declare a variable
D) Import a module
Answer: B

24. In for i in species:, what does i represent?


A) A fixed keyword required by Python
B) A loop variable that can be named anything
C) The index of the species list only
D) A built-in function
Answer: B

25. Which of these are examples of reserved keywords that cannot be used as variable names?
A) and, continue, break
B) name, value, data
C) myVar, x, y
D) print, type, len
Answer: A

26. Variables in Python can contain:


A) Only numbers
B) Only letters
C) Alphanumerical characters and some special characters
D) Only symbols
Answer: C

27. Which of the following is an example of a complex data type in Python?


A) bool
B) complex
C) str
D) int
Answer: B

28. The print() function is used to:


A) Take input from the user
B) Display output on the screen
C) Define a variable
D) Create a loop
Answer: B

29. Which symbol is used for the "less than" comparison?


A) <
B) >
C) <=
D) ==
Answer: A

30. Which symbol is used for "less than or equal to"?


A) <=
B) >=
C) ==
D) !=
Answer: A

31. To find the length of a string, you would typically use:


A) size()
B) length()
C) len()
D) count()
Answer: C

32. x -= y is equivalent to:


A) x = x + y
B) x = y - x
C) x = x - y
D) x = -x - y
Answer: C
33. x *= y is equivalent to:
A) x = x * y
B) x = x + y
C) x = x / y
D) x = y
Answer: A

34. x /= y is equivalent to:


A) x = y / x
B) x = x / y
C) x = x * y
D) x = x - y
Answer: B

35. Which Boolean operator returns True only if both conditions are true?
A) or
B) not
C) and
D) xor
Answer: C

36. Which Boolean operator reverses the result of a condition?


A) and
B) or
C) not
D) equals
Answer: C

37. Which Boolean operator returns True if at least one condition is true?
A) and
B) or
C) not
D) is
Answer: B

38. A dictionary stores data using:


A) Index numbers only
B) Keys and values
C) Tuples of integers
D) Sorted lists
Answer: B

39. In a 10-character string, the index of the second character is:


A) 2
B) 0
C) 1
D) 10
Answer: C

40. To print the third-to-last character of a string, you would use index:
A) -3
B) 3
C) -2
D) 2
Answer: A

41. Slicing a string from index 2 to 8 would be written as:


A) string[2,8]
B) string[2:8]
C) string[2-8]
D) string(2:8)
Answer: B

42. Which of the following is true about tuples?


A) Their contents can be changed after creation
B) Their contents cannot be altered once created
C) They are denoted with []
D) They are slower than lists
Answer: B

43. Which of the following best describes a list in Python?


A) An immutable container
B) A container that can only hold one data type
C) A container of arbitrary type that can be changed
D) A key-value pair structure
Answer: C

44. Why might tuples be preferred over lists in some cases?


A) Tuples are mutable
B) Tuples are faster to access elements from
C) Tuples can store more data types
D) Tuples allow appending elements
Answer: B

45. Which method is used to add an element at the END of a list?


A) insert()
B) append()
C) add()
D) extend()
Answer: B

46. Which method allows inserting an element at a specific position in a list?


A) append()
B) insert()
C) remove()
D) del
Answer: B

47. If you use remove() on a list and the value occurs multiple times, what happens?
A) All instances are removed
B) An error occurs
C) Only the first occurrence is removed
D) Only the last occurrence is removed
Answer: C

48. Which statement is considered better practice for removing an element by position?
A) remove()
B) del with index
C) pop() without index
D) append(None)
Answer: B

49. A for loop is best described as:


A) A conditional statement
B) A way to repeat actions for elements in a sequence
C) A function definition
D) A variable declaration
Answer: B

50. In a for loop like for i in species:, the variable i represents:


A) The length of the list
B) Each element in the list, one at a time
C) The index position only
D) The entire list at once
Answer: B

51. For loops can be used for:


A) Only printing values
B) Only mathematical operations
C) Printing and other operations on each element
D) Only defining functions
Answer: C

52. Which website is mentioned as a resource for learning Python through practical examples?
A) Stack Overflow
B) Code Academy
C) GitHub
D) W3Schools
Answer: B

53. Which other resource is mentioned for learning Python practically?


A) Coursera
B) Data Camp
C) Udemy
D) edX
Answer: B

54. Indexing in Python lists/strings starts at:


A) 1
B) -1
C) 0
D) 10
Answer: C

55. To access elements in reverse order in a list, you use:


A) A plus sign before the index
B) A minus sign before the index
C) Double brackets
D) The reverse() function only
Answer: B

56. Which of the following correctly creates an integer variable x with value 5?
A) x == 5
B) x = 5
C) 5 = x
D) int x = 5
Answer: B

57. A class name, by convention, typically begins with:


A) A lowercase letter
B) A number
C) An uppercase letter
D) An underscore
Answer: C

58. Which of these is an example of a reserved Python keyword?


A) break
B) variable1
C) myList
D) data
Answer: A

59. The type of a variable in Python is determined by:


A) Explicit declaration before use
B) The value assigned to it
C) The order it's created
D) The file extension
Answer: B

60. Which arithmetic operator performs division?


A) *
B) /
C) %
D) **
Answer: B

61. Which arithmetic operator performs multiplication?


A) x
B) *
C) /
D) ^
Answer: B

62. Which arithmetic operator performs addition?


A) +
B) &
C) ++
D) add
Answer: A

63. Which arithmetic operator performs subtraction?


A) -
B) ~
C) //
D) sub
Answer: A

64. Lists in Python are denoted using which brackets?


A) Curly braces {}
B) Square brackets []
C) Parentheses ()
D) Angle brackets <>
Answer: B
65. Tuples in Python are denoted using which brackets?
A) Square brackets []
B) Curly braces {}
C) Parentheses ()
D) Angle brackets <>
Answer: C

66. A dictionary is best described as a:


A) List of integers
B) List of key-value pairs
C) Immutable tuple
D) Single string value
Answer: B

67. Which of the following statements about lists is TRUE?


A) They can only store one type of element
B) Their elements can be of different types
C) They cannot be changed once created
D) They are denoted by ()
Answer: B

68. The for loop iterates over a sequence and:


A) Stops after one element
B) Executes code for each element in the sequence
C) Only works with numbers
D) Cannot be used with lists
Answer: B

69. Which of these correctly demonstrates type casting?


A) Converting an int to a float
B) Declaring a new variable
C) Printing a string
D) Removing a list element
Answer: A

70. The variable naming convention discourages starting variable names with:
A) Lowercase letters
B) Reserved keywords
C) Underscores
D) Letters
Answer: B

You might also like