print("EXAMPLES FOR: str(object) - returns the value of an object, also error handling commands") # we start by assigning a name to a variable value that Python will assign as a floating point decimal Num_test=23.6 + 10 print("The variable assigned: ", end='') print(Num_test) # will print "33.6" without haveing to convert it to a string since it is printed by itself #you can not combine this floating point number with a string without telling Python explicitly that you want it converted to a string #look at how the "str" function is used in the next line print("\nOur test number is a numeric value that we convert to a string to print: " + str(Num_test)) print("But if you try to combine it with a string like 'My value is' + Num_test it causes an error which can be captured and handled easily with try, except, else.\n") # try, except, else, and finally are error control commands for situations where errors are likely try: print ("(1) Trying to use Num_test as a string without explicitly converting it.\n") print("(2) My value is" + Num_test) #this will cause an error that we will handle with except except: print ("Note line one printed fine but line 2 generates this error:\n "+"TypeError: Can't convert 'float' object to str implicitly") print("So the except code was executed.") else: print("you won't get this far")