In Python, type casting is the process of converting one data type to another. Python is a dynamically-typed language, which means that the data type of a variable can change based on the value assigned to it. However, sometimes you may need to convert a variable from one data type to another.
There are several built-in functions in Python that can be used for type casting:
This is a simple program in Python that performs the following operations:
In this program, the user inputs are obtained using the input() function and then cast to integers using int(). The result of the addition of a and b is then stored in c, and to display it, the c is first converted to a string using str() before it's concatenated with the string "Total : " using the + operator. Finally, the result is displayed on the screen using the print() function.
""" a = 10.0 print(a) print(type(a)) b = int(a) print(b) print(type(b)) int() float() str() """ a = int(input("Enter The Value of A : ")) b = int(input("Enter The Value of B : ")) c = a + b print("Total : " + str(c))To download raw file Click Here
Enter The Value of A : 20 Enter The Value of B : 20 Total : 40
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions