Python Forum
why is this variable not printing out properly?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
why is this variable not printing out properly?
#7
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".
Reply


Messages In This Thread
RE: why is this variable not printing out properly? - by sixteenornumber - Dec-27-2016, 02:32 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Printing the variable from defined function jws 7 1,543 Sep-03-2023, 03:22 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020