Posts

Showing posts with the label converting data types in Python

Conversion of data types in Python programming.

Image
​ Conversion of data types: When you are willing to convert one data type into another data type. You may convert a variable into a different type with the int() str() , bool() , or Float () functions, it depends on what form you want your final data type to be.  To add integers and strings, you first have to use  str()  to convert the integer into string. print('I have accomplished ' + str(2) + 'models! ') I have accomplished 2 models! To convert a string to an integer with  int(). print(int('3') + 2) 5 To convert a string to a float with  float(). print(float('6') + 2.0) 8.0 Lastly , to convert objects to boolean values with bool() print (bool(4) , bool(0), bool("hi+g) True False True