Foundations of Programming (Python)
Actual Questions with Answers| Latest Update| Guaranteed Pass
,1. What is the output of the following code?
x = 5
y = 2
print(x // y)
A. 2.5
B. 2
C. 3
D. 2.0
Answer: B
Rationale: The // operator performs floor (integer) division, which divides and
rounds down to the nearest whole number. 5 // 2 equals 2, discarding the
remainder. The / operator would return 2.5 (true division).
2. Which data type is immutable in Python?
A. list
B. dictionary
C. tuple
D. set
Answer: C
Rationale: Tuples are immutable, meaning their contents cannot be changed
after creation. Lists, dictionaries, and sets are all mutable and can be modified
in place after creation.
3. What will the following code print?
fruits = ['apple', 'banana', 'cherry']
print(fruits[-1])
A. apple
B. banana
C. cherry
, D. IndexError
Answer: C
Rationale: Negative indexing counts from the end of the list, where -1 refers to
the last element. fruits[-1] returns 'cherry', the last item in the list.
4. Which keyword is used to define a function in Python?
A. function
B. def
C. func
D. define
Answer: B
Rationale: The 'def' keyword is used to define a function in Python, followed by
the function name, parentheses for parameters, and a colon, e.g., def
my_function():.
5. What is the result of the expression 3 ** 2 in Python?
A. 6
B. 9
C. 5
D. 1
Answer: B
Rationale: The ** operator represents exponentiation. 3 ** 2 means 3 raised to
the power of 2, which equals 9.
6. What is the correct way to create a comment in Python?
A. // This is a comment
B. /* This is a comment */
C. # This is a comment
D.