Type Casting

Lesson Progress
0% Complete

Converting integer to float

int_num = 1
print('Going to convert this identifier\' type\n from INT to >> FLOAT')
print('Type Before: ',type(int_num),'\nType After: ',type(float(int_num)))

Converting float to integer

float_num = 1.0
print('Going to convert this identifier\' type\n from Float to >> Int')
print('Type Before: ',type(float_num),'\nType After: ',type(int(float_num)))

Converting integer to string

int_num = 1
print('Going to convert this identifier\' type\n from INT to >> String')
print('Type Before: ',type(int_num),'\nType After: ',type(str(int_num)))

Converting string to number

string_num = '1'
print('Going to convert this identifier\' type\n from String to >> Int')
print('Type Before: ',type(string_num),'\nType After: ',type(int(string_num)))