Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #65572 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2014-02-07 12:37 +1100 |
| Last post | 2014-02-07 12:37 +1100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Python 2.7.6 help with white spaces? Chris Angelico <rosuav@gmail.com> - 2014-02-07 12:37 +1100
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-02-07 12:37 +1100 |
| Subject | Re: Python 2.7.6 help with white spaces? |
| Message-ID | <mailman.6468.1391737069.18130.python-list@python.org> |
On Fri, Feb 7, 2014 at 12:22 PM, Scott W Dunning <swdunning@cox.net> wrote: > Assume variables exist for minutes and seconds. Each variable is an integer. > How would you create a string in the format, > > 3:11 > > with no spaces. where 3 is minutes and 11 is seconds. > > > Obviously when I⦠> > print minutes, ā:ā, seconds > > I get 3 : 11 > > how can I get it to print with no spaces? > > 3:11 The print statement isn't right for what you're doing here. You need to create a single string with that result, which you could then print out. There are two easy ways to do this. First one is to create a string from the number of minutes, create a string from the number of seconds, and concatenate them, with a third string (the colon) in between. Do you know how to turn an integer into a string, and do you know how to add strings together? The second way is to format the values directly into a single string. You can use printf codes for this. Check this out: http://docs.python.org/2/library/stdtypes.html#string-formatting-operations ChrisA
Back to top | Article view | comp.lang.python
csiph-web