+ 1
Does python really support type casting?
2 Respuestas
+ 5
First of all, x is of type string and not char (because there is no char type im python), and there is no way an integer can be casted to a string.
Second, no Python does not support type casting. Python supports type conversion. There is a difference between the two. See this
https://stackoverflow.com/questions/3166840/what-is-the-difference-between-casting-and-conversion
+ 1
The process of converting the value of one data type (integer, string, float, etc.) to another data type is called type conversion. Python has two types of type conversion.
1. Implicit Type Conversion
2. Explicit Type Conversion
In Implicit type conversion, Python automatically converts one data type to another data type. This process doesn't need any user involvement.
Let's see an example where Python promotes the conversion of the lower data type (integer) to the higher data type (float) to avoid data loss.
https://code.sololearn.com/c72i8O3O692u/?ref=app
In Explicit Type Conversion, users convert the data type of an object to required data type. We use the predefined functions like int(), float(), str(), etc to perform explicit type conversion.
This type of conversion is also called typecasting because the user casts (changes) the data type of the objects.
https://code.sololearn.com/c15mKH4H8Trt/?ref=app