Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #65570 > unrolled thread

Python 2.7.6 help with white spaces?

Started byScott W Dunning <swdunning@cox.net>
First post2014-02-06 18:22 -0700
Last post2014-02-06 23:26 -0500
Articles 4 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Python 2.7.6 help with white spaces? Scott W Dunning <swdunning@cox.net> - 2014-02-06 18:22 -0700
    Re: Python 2.7.6 help with white spaces? Roy Smith <roy@panix.com> - 2014-02-06 20:25 -0500
    Re: Python 2.7.6 help with white spaces? Scott W Dunning <swdunning@cox.net> - 2014-02-06 21:12 -0700
    Re: Python 2.7.6 help with white spaces? Roy Smith <roy@panix.com> - 2014-02-06 23:26 -0500

#65570 — Python 2.7.6 help with white spaces?

FromScott W Dunning <swdunning@cox.net>
Date2014-02-06 18:22 -0700
SubjectPython 2.7.6 help with white spaces?
Message-ID<mailman.6467.1391736132.18130.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

I am having trouble figuring out how to remove spaces….

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

I’m VERY new to python and coding in general and this is a question for a class I’m in for a test review.  So, the most basic answer would be appreciated.  

Thanks for any help!!

Scott


[toc] | [next] | [standalone]


#65571

FromRoy Smith <roy@panix.com>
Date2014-02-06 20:25 -0500
Message-ID<roy-109DF8.20254706022014@news.panix.com>
In reply to#65570
In article <mailman.6467.1391736132.18130.python-list@python.org>,
 Scott W Dunning <swdunning@cox.net> wrote:

> I am having trouble figuring out how to remove spacesŠ.
> 
> 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

print "%d:%02d" % (minutes, seconds)

The "02" for the seconds specifier makes sure you get exactly two 
digits, with a leading zero if needed.

[toc] | [prev] | [next] | [standalone]


#65588

FromScott W Dunning <swdunning@cox.net>
Date2014-02-06 21:12 -0700
Message-ID<mailman.6477.1391746338.18130.python-list@python.org>
In reply to#65570
what exactly is the “%d:%02d”% saying?  



On Feb 6, 2014, at 6:25 PM, Roy Smith <roy@panix.com> wrote:

> In article <mailman.6467.1391736132.18130.python-list@python.org>,
> Scott W Dunning <swdunning@cox.net> wrote:
> 
>> I am having trouble figuring out how to remove spacesŠ.
>> 
>> 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
> 
> print "%d:%02d" % (minutes, seconds)
> 
> The "02" for the seconds specifier makes sure you get exactly two 
> digits, with a leading zero if needed.
> -- 
> https://mail.python.org/mailman/listinfo/python-list

[toc] | [prev] | [next] | [standalone]


#65590

FromRoy Smith <roy@panix.com>
Date2014-02-06 23:26 -0500
Message-ID<mailman.6478.1391747206.18130.python-list@python.org>
In reply to#65570
On Feb 6, 2014, at 11:12 PM, Scott W Dunning wrote:

> what exactly is the “%d:%02d”% saying?  

Python uses string format specifiers similar to C's printf()

%d means, "convert an integer to a decimal string"

%2d means the same, plus, "make the result 2 columns wide"

and, finally, %02d means, "and, if it would normally be less than 2 columns, zero-pad it on the left".

So, putting that all together, we've got:

"%d" --> decimal integer
":" --> a literal ":"
"%02d" --> another decimal integer, this time zero-padded to two columns


> 
> 
> 
> On Feb 6, 2014, at 6:25 PM, Roy Smith <roy@panix.com> wrote:
> 
>> In article <mailman.6467.1391736132.18130.python-list@python.org>,
>> Scott W Dunning <swdunning@cox.net> wrote:
>> 
>>> I am having trouble figuring out how to remove spacesŠ.
>>> 
>>> 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
>> 
>> print "%d:%02d" % (minutes, seconds)
>> 
>> The "02" for the seconds specifier makes sure you get exactly two 
>> digits, with a leading zero if needed.
>> -- 
>> https://mail.python.org/mailman/listinfo/python-list
> 


--
Roy Smith
roy@panix.com


[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web