Casting
Conversion changes a value into another representation when that conversion is defined. It is useful for validated input, but it should not silently hide malformed data.
Understand the idea
int parses whole-number text, float parses suitable fractional text, and str produces text for display. A conversion can raise an exception, so input-handling code needs a clear error path. Converting a float to int truncates toward zero rather than rounding to the nearest whole number.
Where to try it
Open this example with Try in playground. The code loads as editable text and does not run until you select Run. The first run downloads Python. Each run starts fresh; temporary files created by a script are not files on your PC.
A worked example
quantity = int("6")
price = float("2.75")
print(quantity * price)
print(int(-2.9))
Read the result
The outputs are 16.5 and -2. The second shows truncation toward zero, which differs from flooring a negative value.
Try one change
Try a valid count, blank text, and the word six. Decide which inputs your application should accept and how errors should be explained.