Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:Python': 0.05; 'method.': 0.05; 'indexing': 0.07; 'ugly': 0.07; 'received:mail- vb0-f46.google.com': 0.09; 'way:': 0.09; 'thread': 0.11; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'guys,': 0.16; 'losing': 0.16; 'underscores': 0.16; 'mon,': 0.16; 'string': 0.17; 'wrote:': 0.17; 'instance,': 0.17; 'received:209.85.212.46': 0.18; 'feb': 0.19; '(not': 0.20; 'discussion': 0.20; 'otherwise,': 0.20; 'question.': 0.20; 'init': 0.22; 'for?': 0.23; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'implemented': 0.27; 'question': 0.27; 'list:': 0.27; 'message- id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; 'convert': 0.29; 'usually': 0.30; 'normally': 0.30; 'code': 0.31; 'asking': 0.32; 'url:python': 0.32; 'skip:_ 30': 0.32; 'int': 0.33; 'null': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; 'url:org': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'called': 0.39; 'skip:" 10': 0.40; 'leading': 0.61; "you'll": 0.62; 'helps': 0.63; 'subject': 0.66; 'risk': 0.66; 'special': 0.73; 'brand': 0.78; 'directly.': 0.78; '2013': 0.84; 'ever,': 0.84; 'url:datamodel': 0.84; 'url:reference': 0.84; 'old.': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=G3T9sawl5VAo9KuW2jX8JmmX3QOES6VF3K5jUFDFiNQ=; b=YUDMBnbvgXhaor+LubuT9X1/4m1D771215U1P753OVzqQfQvCQQnR24lRDoykX23XE 2gUkKn3HUoj8TtNgwI80WLY8hOU6F+wn56jzfcPMcYeuMmFIfRXnMfxtO6i+qqsAtcOx bmZzFcYL5Ht6yaIr/3KqYj7OkZ9B1/DcJe8bKan46Ji8vg6CXS77oYrU9S1aZlD95DCD KDdv3rH6FUHHg+2uxmFiQqs/8TNyHtg1rULNgug9CEhXrJJL4zq9ceP9KCHfVFjCFqLO lKzr3nli9+lxlxC9ZlrDkFm+p6b4DDtgmdUiaCPc22m90lWqrApHg+QGcv3cVBwI9NxI 9TbA== MIME-Version: 1.0 X-Received: by 10.220.219.77 with SMTP id ht13mr8471038vcb.66.1361721164003; Sun, 24 Feb 2013 07:52:44 -0800 (PST) In-Reply-To: References: <5127848B.1060004@gmail.com> <928d2cf7-728b-4f35-b8c9-4c9b958507e5@googlegroups.com> <8eadd52c-d533-4333-8c7f-7bf3a6d7b046@googlegroups.com> <9p1ii899tkalvfd1cl7sneoqa9t1cqh4oj@invalid.netcom.com> <5129482F.3080402@gmail.com> Date: Mon, 25 Feb 2013 02:52:43 +1100 Subject: Re: Python Newbie From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361721167 news.xs4all.nl 6976 [2001:888:2000:d::a6]:43141 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39752 On Mon, Feb 25, 2013 at 2:46 AM, wrote: > Hi guys, > > Question. Have this code > > intX = 32 # decl + init int var > intX_asString = None # decl + init with NULL string var > > intX_asString = intX.__str__ () # convert int to string > > What are these ugly underscores for? _________________str___________________ Normally you don't need them. Write it this way: intX_asString = str(intX) The "dunder" methods ("d"ouble "under"score, leading and trailing), also called "magic methods", are the implementations of various special features. For instance, indexing foo[1] is implemented using the __getitem__ method. Here's a list: http://docs.python.org/3.3/reference/datamodel.html#special-method-names You'll seldom, if ever, call these methods directly. By the way, when you're asking a completely new question, it usually helps to do so as a brand new thread (not a reply) and with a new subject line. Otherwise, you risk people losing the new question among the discussion of the old. ChrisA