Python 2.7.6 help with white spaces?

Scott W Dunning swdunning at cox.net
Thu Feb 6 23:09:31 EST 2014


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 at gmail.com> wrote:

> On Fri, Feb 7, 2014 at 12:22 PM, Scott W Dunning <swdunning at 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




More information about the Python-list mailing list