1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How do I turn the number 120 to 00120 in python?

  1. Jan 3, 2012 #1
    1. The problem statement, all variables and given/known data

    I need to know how to change the format of a number in python

    for example if I have a integer variable, xstart=0.
    If i were to print(xstart) I want it to show 00000
    and if I were to add 120 to xstart
    xstart+=120
    then print it
    print(xstart) I want it to show 00120

    Thanks.

    2. Relevant equations



    3. The attempt at a solution
     
  2. jcsd
  3. Jan 3, 2012 #2

    Dick

    User Avatar
    Science Advisor
    Homework Helper

    You mean something like this?

    print('%05d' % xstart)

    It is possible to look these things up. That would be a good skill to acquire.
     
    Last edited: Jan 3, 2012
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: How do I turn the number 120 to 00120 in python?
  1. How do I find voltage? (Replies: 3)

Loading...