38.1k views
0 votes
Why did we have to typecast age as a str data type in the print statement?

User Speigg
by
6.6k points

1 Answer

3 votes

Answer: The process of typecasting involves changing a value's data type. The variable "age" in this instance is probably saved as an integer or a float data type, and the print command is converting it to a string data type. This is done so that the text in the print statement and the value of "age" may be concatenated to create a single string that can be printed. The print command will malfunction and throw a TypeError if the variable "age" is not typecasted to a string.

Step-by-step explanation:

User Mossman
by
7.5k points