Dec-27-2016, 02:32 PM
here is one more method.
>>> var1 = 2 + 2 >>> print "the result of all calculations is %s and we are done." % var1 the result of all calculations is 4 and we are done.you can also print floats to a specific decimal place.
>>> PI = 3.14159265389793 >>> print "Pi to the 2nd decimal place is %.02f" %PI Pi to the 2nd decimal place is 3.14 >>> print "Pi to the 3rd decimal place is \"%.03f\" and pi to the 4th decimal place is \"%.04f\"." %(PI, PI) Pi to the 3rd decimal place is "3.141" and pi to the 4th decimal place is "3.1415".