Casting is applied in python to specify the type of data directed to a variable. This is done to increase the accuracy and make the variable more appropriate in terms of holding values.
Some of they ways of casting are as follows:
- int() to hold integer value provided as input
- float() to hold float value provided as input
- str() to hold string value provided as input
let us see some examples to get the ways cleared,
Input for int: x=int(10) print(x) print(type(x))
Output:
Input for float: x=float(10.88) print(x) print(type(x))
Output:
Input for string: x=str("Lingaraj Techhub") print(x) print(type(x))
Output:
Here we come to the end of the topic of discussion on casting in C, hope we were able to clear all your doubts.
Please share and write comments on this post and wants to improve WhatsApp us.