Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28769 > unrolled thread
| Started by | iMath <redstone-cold@163.com> |
|---|---|
| First post | 2012-09-09 06:23 -0700 |
| Last post | 2012-09-10 03:16 -0400 |
| Articles | 4 — 4 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
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
| From | iMath <redstone-cold@163.com> |
|---|---|
| Date | 2012-09-09 06:23 -0700 |
| Subject | Re: Is there any difference between print 3 and print '3' in Python ? |
| Message-ID | <645baeaa-438e-4d30-a559-0db4231ede9c@googlegroups.com> |
在 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
[toc] | [next] | [standalone]
| From | Ian Foote <ian@feete.org> |
|---|---|
| Date | 2012-09-09 15:41 +0100 |
| Message-ID | <mailman.420.1347201717.27098.python-list@python.org> |
| In reply to | #28769 |
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 The difference is that 3 is an integer whereas '3' is a string. The print statement (function in python 3) converts any object to a string before displaying it on the screen, so print 3 and print '3' both display the same result. Ian F
[toc] | [prev] | [next] | [standalone]
| From | Benjamin Kaplan <benjamin.kaplan@case.edu> |
|---|---|
| Date | 2012-09-09 23:55 -0700 |
| Message-ID | <mailman.434.1347260169.27098.python-list@python.org> |
| In reply to | #28769 |
On Sun, Sep 9, 2012 at 11:33 PM, Dwight Hutto <dwightdhutto@gmail.com> wrote:
>
>
> On Sun, Sep 9, 2012 at 10:41 AM, Ian Foote <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.
> --
> Best Regards,
> David Hutto
> CEO: http://www.hitwebdevelopment.com
>
Somewhat OT, but __future__ doesn't work like that. You have to import
the specific features you want to use.
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> print 3
3
>>> import __future__
>>> print 3
3
>>> from __future__ import print_function
>>> print 3
File "<stdin>", line 1
print 3
^
SyntaxError: invalid syntax
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2012-09-10 03:16 -0400 |
| Message-ID | <mailman.437.1347261438.27098.python-list@python.org> |
| In reply to | #28769 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web