Table of Contents
Example Description
This Python code demonstrates explicit type conversion and string concatenation using the variables 'icecream' and 'brownie'.

Introduction:

This Python code showcases how to perform explicit type conversion and string concatenation. It uses the variables ‘icecream’ and ‘brownie’ to calculate the total price of both items.

Code:

#Explicit type conversion
icecream = '25'
brownie = '45'
#String concatenation
price = icecream + brownie
print("Total Price Rs." + price)
#Explicit type conversion - string to integer
price = int(icecream)+int(brownie)
print("Total Price Rs." + str(price))

Logic:

1. The code initializes two variables, ‘icecream’ and ‘brownie’, with string values representing the respective prices.
2. The code performs string concatenation using the ‘price’ variable, combining the values of ‘icecream’ and ‘brownie’.
3. The code then prints the total price in a formatted message.
4. Next, the code performs explicit type conversion by converting the values of ‘icecream’ and ‘brownie’ from strings to integers.
5. The code adds the converted values of ‘icecream’ and ‘brownie’ to calculate the total price as an integer.
6. The code converts the total price back to a string and concatenates it with the message to display the total price in a formatted message.

Output:

>> Total Price Rs.2545

>> Total Price Rs.70