[Tutor] end parameter in 2.7.1?
Peter Otten
__peter__ at web.de
Sat Jan 15 21:42:50 CET 2011
Bill DeBroglie wrote:
> Twice in two days...!
>
> Using Mac OS X 10.5.8 and Python 2.7.1 but am following a book which
> is using Python 3.1. The author uses the end parameter in numerous
> programs but this doesn't seem to translate to 2.7. Any advice as to
> how I can specify the final string of the print function?
You can trick 2.7 into behaving similar to 3.x in that respect with a from
__future__ import:
Python 2.7.1 (r271:86832, Jan 5 2011, 10:42:58)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import print_function
>>> print("you are asking for trouble", end="!\n")
you are asking for trouble!
However, I recommend that you install Python 3.1 in addition to 2.7 and use
3.1 to learn the language. If you don't you'll run into a lot of tiny but
frustrating differences.
More information about the Tutor
mailing list