Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28806
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: Is there any difference between print 3 and print '3' in Python ? |
| Date | 2012-09-10 03:16 -0400 |
| References | <5128580.32.1332762326119.JavaMail.geo-discussion-forums@pbom7> <645baeaa-438e-4d30-a559-0db4231ede9c@googlegroups.com> <504CAAAA.3090905@feete.org> <CA+vVgJX2xg4KQJq2eVSpj-PMax81mpUJ4BQpT-iPdB0FgP_0eQ@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.437.1347261438.27098.python-list@python.org> (permalink) |
On 9/10/2012 2:33 AM, Dwight Hutto wrote:
>
>
> On Sun, Sep 9, 2012 at 10:41 AM, Ian Foote <ian@feete.org
> <mailto:ian@feete.org>> wrote:
>
> On 09/09/12 14:23, iMath wrote:
>
> 在 2012年3月26日星期一UTC+8下午7时45分26秒,__iMath写道:
>
> 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 ?
>
> thx everyone
>
>
> Here's a future import though I used,so I can use the planned 3 with a
> 2x python version in the command line interpreter:
>
> Microsoft Windows [Version 6.1.7600]
> Copyright (c) 2009 Microsoft Corporation. All rights reserved.
>
> C:\Users\david>c:\python26\python.exe
> Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit
> (Intel)] on
> win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> exit()
>
> C:\Users\david>c:\python27_64\python.exe
> Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit
> (AMD64)] on win
> 32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import __future__
> >>> x = 3
> >>> y = '3'
> >>> print(x)
> 3
> >>> print(y)
> 3
> >>>
> >>> type(x)
> <type 'int'>
> >>> type(y)
> <type 'str'>
>
> >>> z = '%i' % (3)
> >>> type(z)
> <type 'str'>
> >>>
>
> In other words type(value), and find out the difference.
print(x) prints str(x), which is meant to be a 'friendly'
representation. To see a difference,
>>> print(repr(3))
3
>>> print(repr('3'))
'3'
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: Is there any difference between print 3 and print '3' in Python ? iMath <redstone-cold@163.com> - 2012-09-09 06:23 -0700 Re: Is there any difference between print 3 and print '3' in Python ? Ian Foote <ian@feete.org> - 2012-09-09 15:41 +0100 Re: Is there any difference between print 3 and print '3' in Python ? Benjamin Kaplan <benjamin.kaplan@case.edu> - 2012-09-09 23:55 -0700 Re: Is there any difference between print 3 and print '3' in Python ? Terry Reedy <tjreedy@udel.edu> - 2012-09-10 03:16 -0400
csiph-web