Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'string.': 0.05; 'subject:Python': 0.06; 'result,': 0.07; 'variables': 0.07; 'subject:help': 0.08; 'string': 0.09; 'cc:addr:python-list': 0.11; 'assume': 0.14; 'between.': 0.16; 'concatenate': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'integer.': 0.16; 'seconds,': 0.16; 'seconds.': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'variable': 0.18; '(the': 0.22; 'feb': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'format,': 0.24; 'integer': 0.24; 'string,': 0.24; 'cc:2**0': 0.24; 'second': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; 'this.': 0.32; 'url:python': 0.33; 'fri,': 0.33; 'third': 0.33; 'could': 0.34; 'subject:with': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'minutes,': 0.36; 'doing': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'seconds': 0.37; 'turn': 0.37; 'two': 0.37; 'url:library': 0.38; 'pm,': 0.38; 'how': 0.40; 'easy': 0.60; "you're": 0.61; 'first': 0.61; 'minutes': 0.67; 'to:none': 0.92; 'scott': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=8+YYr/M/bSnZ1wnhR9n4yjC/Agz8lNjHTvui9N9OZ9I=; b=0cHwvbKhJBfPAkOAkp4864H1RFGPUreMrfvGtMZBcmGcxzmbjjSdElDURiSzp0rnoX PzrzGKA2yCHmV5vj0SE7hZOHedm3mhrXkmwAKx2xiWKxy4g7UMdadORVMjmom1ejPKUu wl1iMAtUB++Inz/1iUdVatJcM6gZE3mnwkaa7IjNbpSiNgbMAyjMmdAMjU5djCRbivMF 7/fi9zXndwTAPXHCc34NureKQ8EkAtI76KYK0cW9JJMGlPePyI9//coZZHC81njWbrOk dwBrRBH3V9uOWBYREmHNqWGs9AE+dajmPi62OQYwY3jsLGWJUGwuNLPUR1IAjagrRy/a gtmA== MIME-Version: 1.0 X-Received: by 10.68.247.6 with SMTP id ya6mr16023386pbc.45.1391737066728; Thu, 06 Feb 2014 17:37:46 -0800 (PST) In-Reply-To: References: Date: Fri, 7 Feb 2014 12:37:46 +1100 Subject: Re: Python 2.7.6 help with white spaces? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391737069 news.xs4all.nl 2854 [2001:888:2000:d::a6]:37755 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65572 On Fri, Feb 7, 2014 at 12:22 PM, Scott W Dunning wrote: > Assume variables exist for minutes and seconds. Each variable is an integ= er. > 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=E2=80=A6 > > print minutes, =E2=80=9C:=E2=80=9D, 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