PCEP Fundamentals of Python Programming 2 — Questions and Answers
Question 1: What is the output of `print(type(3.0))` in Python?
- <class 'int'>
- <class 'float'> (Correct answer)
- <class 'double'>
- <class 'number'>
Correct answer: <class 'float'>
3.0 is a floating-point literal, so its type is `float`.
Question 2: Which operator is used for integer (floor) division in Python?
- /
- %
- // (Correct answer)
- **
Correct answer: //
The `//` operator performs floor division, discarding the fractional part.
Question 3: What value does `bool('')` return?
- True
- False (Correct answer)
- None
- Error
Correct answer: False
An empty string is falsy in Python, so `bool('')` returns `False`.
Question 4: What is the result of `10 % 3` in Python?
- 3
- 1 (Correct answer)
- 0
- 3.33
Correct answer: 1
The modulo operator `%` returns the remainder of 10 divided by 3, which is 1.
Question 5: Which of the following is a valid Python identifier?
- 2name
- my-var
- _count (Correct answer)
- class
Correct answer: _count
`_count` is valid because identifiers can start with an underscore, but not a digit or hyphen, and cannot be reserved keywords.
Question 6: What does the `len()` function return when called on the string `'hello'`?
- 4
- 5 (Correct answer)
- 6
- None
Correct answer: 5
`len('hello')` returns 5 because there are five characters in the string.
Question 7: In Python, what is the result of `'3' + '4'`?
- 7
- 34 (Correct answer)
- '34'
- Error
Correct answer: 34
String concatenation with `+` joins the two string literals, resulting in `'34'`.
What is the output of `print(type(3.0))` in Python?