Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Variables can be interpreted as strings by converting them to a string data type through typecasting. This is done by enclosing the variable name in either single or double quotes. For example, if a variable named "age" containing the value 25 needs to be interpreted as a string, it can be done as follows:

age = 25
age_string = str(age)
print("The person's age is " + age_string + " years old.")

Output:

The person's age is 25 years old.

In this example, the variable "age" is first converted to a string using the str() function and then concatenated to other strings using the + operator.