24th Nov 2020, 4:41 AM
ClassHacker
ClassHacker - avatar
2 Antworten
+ 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
24th Nov 2020, 4:48 AM
XXX
XXX - avatar
+ 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
24th Nov 2020, 8:09 AM
Iman Gharaee
Iman Gharaee - avatar