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 is the result of evaluating int("42") in Python?
Answer: 42 (an integer)
int() converts a valid string representation of a whole number to an integer, so int("42") returns the integer 42.
What does float("3.14") return in Python?
Answer: 3.14 (a float)
float() converts a valid string representation of a decimal number into a floating-point value, returning 3.14.
What is the result of str(100) in Python?
Answer: "100" (a string)
str() converts any value to its string representation, so str(100) returns the string "100".
What does bool(0) return in Python?
Answer: False
In Python, 0 is falsy, so bool(0) returns False.
What is the result of int(3.9) in Python?
Answer: 3 (truncates toward zero)
int() truncates the decimal portion toward zero, so int(3.9) returns 3, not 4.
What happens when you execute int("hello") in Python?
Answer: Raises a ValueError
int() raises a ValueError when given a string that cannot be interpreted as an integer.
Which of the following is the correct output of type(3.14) in Python?
Answer:
type() returns the class object itself, and its repr is for floating-point values.