0% found this document useful (0 votes)
8 views17 pages

Python Data Types and Expressions Quiz

This document contains a series of questions and answers related to Python programming, covering topics such as data types, expressions, statements, and basic operations. It includes multiple-choice questions with correct answers indicated for each. The content serves as a study guide for understanding Python fundamentals.

Uploaded by

renuka
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)
8 views17 pages

Python Data Types and Expressions Quiz

This document contains a series of questions and answers related to Python programming, covering topics such as data types, expressions, statements, and basic operations. It includes multiple-choice questions with correct answers indicated for each. The content serves as a study guide for understanding Python fundamentals.

Uploaded by

renuka
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

UNIT II - DATA TYPES, EXPRESSIONS, STATEMENTS

1. Which of the following runs Python code line by line?


a) Compiler
b) Interpreter
c) Assembler
d) Preprocessor
Answer: b) Interpreter
2. In interactive mode, Python statements are executed:
a) After the entire program is saved
b) Immediately after pressing Enter
c) Only if run as a script
d) Only inside functions
Answer: b) Immediately after pressing Enter
3. A Python file saved with .py extension is executed in:
a) Script mode
b) Interactive mode
c) Debug mode
d) Console mode
Answer: a) Script mode
4. The default Python prompt in interactive mode is:
a) ?
b) >>>
c) :::
d) $$
Answer: b) >>>
5. To exit Python interactive mode, we can use:
a) quit()
b) exit()
c) Ctrl+Z (Windows) or Ctrl+D (Linux/Mac)
d) All of the above
Answer: d) All of the above

6. Which of these is a valid int value in Python?


a) 12.5
b) -15
c) "25"
d) True
Answer: b) -15
7. What is the type of 3.14 in Python?
a) int
b) float
c) str
d) bool
Answer: b) float
8. The Boolean value of bool(0) is:
a) True
b) False
c) Error
d) None
Answer: b) False
9. Which of the following is a string literal in Python?
a) 'Hello'
b) "Python"
c) """World"""
d) All of the above
Answer: d) All of the above
10. Which of the following represents a list?
a) {1, 2, 3}
b) (1, 2, 3)
c) [1, 2, 3]
d) "1,2,3"
Answer: c) [1, 2, 3]

11. Which symbol is used for assignment in Python?


a) =
b) ==
c) :=
d) ->
Answer: a) =
12. Which of the following is a valid variable name?
a) 2num
b) num_2
c) num-2
d) @num
Answer: b) num_2
13. An expression in Python always produces a:
a) Variable
b) Statement
c) Value
d) Function
Answer: c) Value
14. Which of these is a valid statement?
a) x = 10
b) print("Hello")
c) pass
d) All of the above
Answer: d) All of the above
15. The keyword pass in Python means:
a) Skip execution
b) Placeholder for future code
c) Break loop
d) Continue loop
Answer: b) Placeholder for future code
16. Tuple assignment a, b = 5, 10 results in:
a) Error
b) a = (5, 10), b = None
c) a = 5, b = 10
d) a = 10, b = 5
Answer: c) a = 5, b = 10
17. Which operator has the highest precedence in Python?
a) +
b) -
c) **
d) *
**Answer: c) **
18. In Python, 2 + 3 * 4 evaluates to:
a) 20
b) 14
c) 24
d) 120
Answer: b) 14
19. The expression (2 + 3) * 4 evaluates to:
a) 20
b) 14
c) 24
d) 120
Answer: a) 20
20. In Python, not True or False evaluates to:
a) True
b) False
c) None
d) Error
Answer: b) False

21. In Python, a single-line comment starts with:


a) //
b) <!--
c) #
d) --
Answer: c) #
22. Multi-line comments in Python are usually written using:
a) /* … */
b) """ … """
c) // … //
d) -- … --
Answer: b) """ … """
23. What happens if a comment is written in Python?
a) It is ignored during execution
b) It produces an error
c) It is stored in memory
d) It changes program speed
Answer: a) It is ignored during execution
24. Which of the following is a valid comment line?
a) ## This is a comment
b) #This is a comment
c) # This is a comment
d) All of the above
Answer: d) All of the above
25. Comments are used for:
a) Explaining code
b) Debugging help
c) Ignored by interpreter
d) All of the above
Answer: d) All of the above

26. Which of the following swaps the values of x and y in Python?


a) x, y = y, x
b) swap(x, y)
c) x = y; y = x
d) x := y
Answer: a) x, y = y, x
27. After executing a, b, c = 1, 2, 3; a, b, c = b, c, a, the value of a is:
a) 1
b) 2
c) 3
d) None
Answer: b) 2
28. If a, b, c = 10, 20, 30 and then a, b, c = c, a, b, the final values are:
a) a=20, b=30, c=10
b) a=30, b=10, c=20
c) a=10, b=20, c=30
d) a=10, b=30, c=20
Answer: b) a=30, b=10, c=20
29. The most Pythonic way to exchange two variables is:
a) Using a temporary variable
b) Using arithmetic operations (+, -)
c) Using x, y = y, x
d) Using bitwise XOR
Answer: c) Using x, y = y, x
30. What will be printed?

x, y, z = 1, 2, 3
x, y, z = z, x, y
print(x, y, z)

a) 3 1 2
b) 1 2 3
c) 2 3 1
d) 3 2 1
Answer: a) 3 1 2
31. The formula to compute distance between points (x1, y1) and (x2, y2) is:
a) (x2 - x1) + (y2 - y1)
b) (x2 - x1) * (y2 - y1)
c) ((x2 - x1)**2 + (y2 - y1)**2) ** 0.5
d) abs(x2 - x1) + abs(y2 - y1)
**Answer: c) ((x2 - x1)**2 + (y2 - y1)2) ** 0.5
32. In Python, to import the square root function, we write:
a) import [Link]
b) from math import sqrt
c) math sqrt
d) sqrt(math)
Answer: b) from math import sqrt
33. What will be the output?

import math
x1, y1, x2, y2 = 0, 0, 3, 4
dist = [Link]((x2-x1)**2 + (y2-y1)**2)
print(dist)

a) 5
b) 7
c) 25
d) 2.5
Answer: a) 5

34. Which data type is returned by [Link](25)?


a) int
b) float
c) str
d) bool
Answer: b) float
35. If dist = ((6-2)**2 + (8-5)**2)**0.5, what is the value of dist?
a) 25
b) 10
c) 5
d) 2
Answer: c) 5

36. What is the result of 2 ** 3 ** 2?


a) 64
b) 512
c) 256
d) 16
Answer: b) 512 (right-to-left evaluation)
37. In Python, not 0 evaluates to:
a) 0
b) 1
c) True
d) False
Answer: c) True
38. The result of 7 // 2 is:
a) 3.5
b) 3
c) 4
d) 2
Answer: b) 3
39. The result of 7 % 2 is:
a) 0
b) 1
c) 2
d) 3
Answer: b) 1
40. The result of 2 * 3 ** 2 is:
a) 36
b) 18
c) 12
d) 9
Answer: b) 18

41. What is the output?

a, b = 5, 2
print(a / b)

a) 2
b) 2.5
c) 2.0
d) Error
Answer: b) 2.5

42. What is the output?

a, b = 5, 2
print(a // b)

a) 2.5
b) 2
c) 3
d) Error
Answer: b) 2

43. What is the output?

x = True
y = False
print(x and y)

a) True
b) False
c) Error
d) None
Answer: b) False

44. What is the output?

x = "10"
y = 5
print(x * y)

a) 50
b) "10" * 5 → "1010101010"
c) Error
d) "50"
Answer: b) "1010101010"

45. What is the output?

x = [1, 2, 3]
print(x * 2)

a) [1, 2, 3, 1, 2, 3]
b) [2, 4, 6]
c) [1, 2, 3, 2]
d) Error
Answer: a) [1, 2, 3, 1, 2, 3]

46. What is the output?

x = "Python"
print(x[0])

a) P
b) y
c) n
d) Error
Answer: a) P

47. What is the output?

x = "Python"
print(x[-1])

a) P
b) n
c) o
d) Error
Answer: b) n

48. What is the output?

x = [10, 20, 30, 40]


print(x[1:3])
a) [10, 20, 30]
b) [20, 30]
c) [30, 40]
d) Error
Answer: b) [20, 30]

49. What is the output?

x = [1, 2, 3]
y = x
[Link](4)
print(x)

a) [1, 2, 3]
b) [1, 2, 3, 4]
c) [4]
d) Error
Answer: b) [1, 2, 3, 4]

50. What is the output?

a = 10
b = 20
print(a == b)

a) True
b) False
c) Error
d) None
Answer: b) False

51. What is the output?

x = [1, 2, 3]
print(len(x))

a) 2
b) 3
c) 4
d) Error
Answer: b) 3

52. Which of the following methods adds an element to the end of a list?
a) add()
b) append()
c) insert()
d) extend()
Answer: b) append()
53. Which method is used to add multiple elements to a list at once?
a) add()
b) insert()
c) append()
d) extend()
Answer: d) extend()
54. What is the output?

x = [1, 2, 3]
[Link](1, 99)
print(x)

a) [1, 99, 2, 3]
b) [99, 1, 2, 3]
c) [1, 2, 99, 3]
d) Error
Answer: a) [1, 99, 2, 3]

55. Which method removes and returns the last element of a list?
a) remove()
b) delete()
c) pop()
d) discard()
Answer: c) pop()
56. What is the output?

x = [10, 20, 30]


print([Link]())

a) 10
b) 20
c) 30
d) Error
Answer: c) 30

57. What is the output?

x = [1, 2, 3, 4, 5]
print(x[::2])

a) [1, 2, 3]
b) [1, 3, 5]
c) [2, 4]
d) Error
Answer: b) [1, 3, 5]

58. What is the output?

x = [1, 2, 3]
y = x * 2
print(y)
a) [2, 4, 6]
b) [1, 2, 3, 1, 2, 3]
c) [1, 2, 3]
d) Error
Answer: b) [1, 2, 3, 1, 2, 3]

59. What is the output?

x = [1, 2, 3]
print(2 in x)

a) True
b) False
c) Error
d) None
Answer: a) True

60. What is the output?

x = [1, 2, 3]
print(5 not in x)

a) True
b) False
c) Error
d) None
Answer: a) True

61. What is the output?

s = "Python"
print([Link]())

a) python
b) PYTHON
c) Python
d) Error
Answer: b) PYTHON

62. What is the output?

s = "Python"
print([Link]())

a) PYTHON
b) python
c) Python
d) Error
Answer: b) python

63. What is the output?


s = "python programming"
print([Link]())

a) Python programming
b) Python Programming
c) Pythonprogramming
d) Error
Answer: b) Python Programming

64. What is the output?

s = "Python"
print(s[1:4])

a) Pyt
b) yth
c) ytho
d) tho
Answer: b) yth

65. What is the output?

s = "Python"
print(s[::-1])

a) Python
b) nohtyP
c) Error
d) Pytho
Answer: b) nohtyP

66. What is the result of True and False or True?


a) True
b) False
c) Error
d) None
Answer: a) True (because and first → False or True = True)
67. What is the result of not (True and False)?
a) True
b) False
c) Error
d) None
Answer: a) True
68. What is the result of (10 > 5) and (5 < 3)?
a) True
b) False
c) Error
d) None
Answer: b) False
69. What is the result of (5 == 5) or (3 != 3)?
a) True
b) False
c) Error
d) None
Answer: a) True
70. What is the result of not 0 in Python?
a) 0
b) 1
c) True
d) False
Answer: c) True

71. What is the output of 3 + 2 * 2?


a) 10
b) 7
c) 12
d) 8
Answer: b) 7
72. What is the output of (3 + 2) * 2?
a) 7
b) 10
c) 12
d) 8
Answer: b) 10
73. What is the result of 2 ** 3 ** 2?
a) 64
b) 512
c) 256
d) 16
Answer: b) 512
74. What is the result of 4 + 3 % 5?
a) 7
b) 2
c) 3
d) 4
Answer: a) 7
75. What is the result of 5 * 2 // 3?
a) 3.33
b) 3
c) 10
d) 2
Answer: b) 3

76. What is the output of 7 / 2 in Python 3?


a) 3
b) 3.5
c) 4
d) Error
Answer: b) 3.5
77. What is the output of 7 // 2 in Python?
a) 3
b) 3.5
c) 4
d) Error
Answer: a) 3
78. What is the output of 7 % 2?
a) 1
b) 2
c) 3
d) 0
Answer: a) 1
79. Which of the following is not a valid statement in Python?
a) x = 10
b) print("Hello")
c) 10 = x
d) pass
Answer: c) 10 = x
80. A statement that does nothing in Python is written as:
a) null
b) pass
c) skip
d) continue
Answer: b) pass

81. What is the output?

a, b = 5, 10
a, b = b, a
print(a, b)

a) 5 10
b) 10 5
c) 15 15
d) Error
Answer: b) 10 5

82. What is the output?

a, b, c = 1, 2, 3
a, b, c = c, a, b
print(a, b, c)

a) 1 2 3
b) 3 1 2
c) 2 3 1
d) Error
Answer: b) 3 1 2

83. Tuple assignment allows:


a) Multiple values to be assigned in one line
b) Value swapping without temporary variable
c) Circulation of values
d) All of the above
Answer: d) All of the above
84. What will happen?

a, b = 5, 10, 15

a) a=5, b=10
b) a=5, b=10, 15 ignored
c) Error (too many values to unpack)
d) None
Answer: c) Error (too many values to unpack)

85. What is the output?

a, b, c = 10, 20, 30
a, b, c = b, c, a
print(c)

a) 10
b) 20
c) 30
d) Error
Answer: a) 10

86. What is the output?

x = [1, 2, 3]
print(x[1:])

a) [1]
b) [1, 2]
c) [2, 3]
d) [3]
Answer: c) [2, 3]

87. What is the output?

x = "hello"
print(x[1:4])

a) hel
b) ell
c) llo
d) hlo
Answer: b) ell

88. What is the output?

x = "abc" * 3
print(x)
a) abcabcabc
b) abc*3
c) abcabc
d) Error
Answer: a) abcabcabc

89. Which of these methods is used to find the position of a substring?


a) index()
b) find()
c) search()
d) Both a and b
Answer: d) Both a and b
90. What is the output?

s = "banana"
print([Link]("a"))

a) 2
b) 3
c) 4
d) Error
Answer: b) 3

91. A single-line comment in Python starts with:


a) //
b) #
c) <!--
d) ;;
Answer: b) #
92. Multi-line comments are usually written using:
a) /* … */
b) """ … """
c) // … //
d) -- … --
Answer: b) """ … """
93. What happens to comments during execution?
a) Executed normally
b) Ignored by interpreter
c) Stored as metadata
d) Cause error
Answer: b) Ignored by interpreter
94. Which of the following is a valid comment line?
a) # This is a comment
b) ## Another comment
c) #Comment without space
d) All of the above
Answer: d) All of the above
95. Comments in Python are mainly used for:
a) Improving code readability
b) Debugging
c) Documentation
d) All of the above
Answer: d) All of the above

96. What is the output of the following swap program?

a, b = 10, 20
a, b = b, a
print(a, b)

a) 10 20
b) 20 10
c) 30 30
d) Error
Answer: b) 20 10

97. What is the output?

a, b, c = 1, 2, 3
a, b, c = b, c, a
print(a, b, c)

a) 1 2 3
b) 2 3 1
c) 3 1 2
d) Error
Answer: b) 2 3 1

98. Distance program: If (x1, y1) = (0,0) and (x2, y2) = (6,8), the distance is:
a) 10
b) 14
c) 5
d) 12
Answer: a) 10
99. What will be printed?

x, y = 5, 10
x, y = y, x + y
print(x, y)

a) 10 15
b) 5 10
c) 15 10
d) Error
Answer: a) 10 15

100. What will be the output?


x, y, z = 1, 2, 3
x, y, z = z, x, y
print(z)

a) 1
b) 2
c) 3
d) Error
Answer: b) 2

You might also like