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


Groups > comp.lang.python > #65587

Re: Python 2.7.6 help with white spaces?

Subject Re: Python 2.7.6 help with white spaces?
From Scott W Dunning <swdunning@cox.net>
Date 2014-02-06 21:09 -0700
References <DC365E9C-9511-49BD-A53F-67B4ED3A561F@cox.net> <PDfx1n00t3bjUJS01Dfz59>
Newsgroups comp.lang.python
Message-ID <mailman.6476.1391746182.18130.python-list@python.org> (permalink)

Show all headers | View raw


Is this what you’re talking about?  

minutes = “3”
seconds = “11”

print int(minutes), ”:" int(seconds)

That’s what you mean by turning a string into an int right?  Not sure how to add strings together though.



On Feb 6, 2014, at 6:37 PM, Chris Angelico <rosuav@gmail.com> wrote:

> 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
> -- 
> https://mail.python.org/mailman/listinfo/python-list

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Python 2.7.6 help with white spaces? Scott W Dunning <swdunning@cox.net> - 2014-02-06 21:09 -0700

csiph-web