Type Conversion and Built-in Functions Flashcards
7 cards from real PCEP practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Type Conversion and Built-in Functions flashcards as text
What does bool("") return in Python?
Answer: False
An empty string is falsy in Python, so bool("") returns False.
What does bool("False") return in Python?
Answer: True
Any non-empty string is truthy in Python, so bool("False") returns True regardless of the string's content.
What is the result of int(True) in Python?
Answer: 1 (integer)
In Python, True is a subclass of int with the value 1, so int(True) returns 1.
What does float(False) return in Python?
Answer: 0.0 (float)
False has an integer value of 0, and float() converts that to 0.0.
What does list(range(4)) produce in Python?
Answer: [0, 1, 2, 3]
list() converts the range object to a list; range(4) generates 0 through 3, giving [0, 1, 2, 3].
What is the output of sorted([3, 1, 4, 1, 5, 9])?
Answer: [1, 1, 3, 4, 5, 9]
sorted() returns a new list with all elements sorted in ascending order, preserving duplicates.
What does len([1, [2, 3], 4]) return in Python?
Answer: 3
len() counts only the top-level elements; the list has 3 items: 1, [2, 3], and 4.