Table of Contents
Example Description
Learn how to use explicit type casting in Python to calculate the total price by adding two price variables. Example code included


This Python code demonstrates the concept of explicit type casting. It calculates the total price by adding two price variables, priceIcecream and priceBrownie, and then converts the result to a string for display.


priceIcecream = 25
priceBrownie = 45
totalPrice = priceIcecream + priceBrownie
print("The total in Rs." + str(totalPrice))


  1. The code initializes two variables, priceIcecream and priceBrownie, with the respective prices.
  2. It then adds the two variables together and stores the result in the totalPrice variable.
  3. Finally, it converts the totalPrice to a string using the str() function and concatenates it with the string “The total in Rs.” to form the desired output.


>> The total in Rs.70