Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.018 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; "subject:' ": 0.07; 'subject:Python': 0.07; 'literal': 0.09; 'stack.': 0.09; 'python': 0.11; 'print': 0.15; "'',": 0.16; 'difference,': 0.16; 'enigma': 0.16; 'executed': 0.16; 'instruction.': 0.16; 'kern': 0.16; 'received:80.91': 0.16; 'received:80.91.229': 0.16; 'received:gmane.org': 0.16; 'received:list': 0.16; 'subject:between': 0.16; 'underlying': 0.16; 'robert': 0.18; 'wrote:': 0.21; 'produces': 0.22; 'statement': 0.22; 'header:In- Reply-To:1': 0.22; 'header:User-Agent:1': 0.23; 'import': 0.24; 'pm,': 0.28; 'skip:d 30': 0.29; 'gets': 0.32; 'two': 0.35; 'there': 0.35; 'onto': 0.35; 'see,': 0.35; 'header:X-Complaints- To:1': 0.36; 'but': 0.36; 'received:org': 0.38; 'to:addr:python- list': 0.39; 'to:addr:python.org': 0.40; 'happen': 0.63; 'yes,': 0.63; 'our': 0.64; 'between': 0.64; 'world': 0.65; 'believe': 0.67; "'3'": 0.84; '12:45': 0.84; 'subject:there': 0.84; 'terrible': 0.84; 'eco': 0.91; 'output,': 0.91; 'email addr:163.com': 0.97 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Robert Kern Subject: Re: Is there any difference between print 3 and print '3' in Python ? Date: Mon, 26 Mar 2012 13:10:55 +0100 References: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 94.197.127.115.threembb.co.uk User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:11.0) Gecko/20120313 Thunderbird/11.0 In-Reply-To: <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1332763876 news.xs4all.nl 6951 [2001:888:2000:d::a6]:43205 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22180 On 3/26/12 12:45 PM, redstone-cold@163.com wrote: > I know the print statement produces the same result when both of these two instructions are executed ,I just want to know Is there any difference between print 3 and print '3' in Python ? Yes, there is a difference, but not much. [~] |6> import dis [~] |7> dis.disassemble(compile('print 3', '', 'exec')) 1 0 LOAD_CONST 0 (3) 3 PRINT_ITEM 4 PRINT_NEWLINE 5 LOAD_CONST 1 (None) 8 RETURN_VALUE [~] |8> dis.disassemble(compile('print "3"', '', 'exec')) 1 0 LOAD_CONST 0 ('3') 3 PRINT_ITEM 4 PRINT_NEWLINE 5 LOAD_CONST 1 (None) 8 RETURN_VALUE As you can see, the only difference is in the first instruction. Both of these put the object that you specified by the literal onto the stack. The difference is that one is the int object specified by the literal 3 and the other is the str object specified by the literal "3". Both of these objects happen to give the same __str__ output, so that's what gets printed. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco