Menu

Casting

Card 1 of 16 0 got it 0 still learning
Question
TapClick or press space to see the answer
Answer
All 16 cards in this set
Which term describes converting a value from one data type to another data type?
Casting
What does the casting function int() do when it is applied to the string '42'?
It converts the string into an integer for use in calculations
Which casting function converts a string such as '4.52' into a real number?
The float() function, which keeps the decimal part
What is meant by the casting function str()?
It converts a value into a string so that it can be joined to text
What is meant by truncating a real number when it is cast to an integer?
The fractional part is cut off, so 4.99 becomes 4
Which value gives False when it is cast with bool()?
The empty string
A variable called score holds the integer 10. The statement float(score) runs on its own. What does score hold afterwards?
The integer 10
A value typed in by the user is stored as a string. Why must int() be used on it before it is used in a calculation?
The value is a string, so it must become a number for arithmetic
What is the value of bool('False')?
True
What is the result of int('12') + int('3')?
15
What is the value of float(7)?
7.0
Which of these will cause the program to stop with an error when int() is used on it?
The string '3.5'
A program runs the code int('7') + '3'. What happens?
The program stops with an error
A variable called answer holds the string 'False'. A program needs the Boolean value False. What should it do?
Compare answer with the text 'False'
The variable price holds the string '2.5'. What is the value of float(price) + 2?
4.5
What is the result of str(12) + str(3)?
The text '123'