On 03/08/12 22:09, Alexander Q. wrote:
That was it Jerry- when I typed in "print hello" instead of just
"hello", the output was exactly like the one in the tutorial.
Yes, the interactive interpreter shows the representation
(repr()) of the data while print shows the normal output. There are
several places where this difference is significant.
Alternatively, I could accomplish the same type of output by using
triple quotes around the same text, except that I would have to format
it manually if I want it to come out looking the same
Nope, that won;t work either, try it:
>>> s = """Here is
... a string
... with
... line
... breaks"""
>>> s
'Here is \na string\nwith\nline\nbreaks'
>>> print s
Here is
a string
with
line
breaks
>>>
Again repr() just prints the newline characters.
I understand it from your explanation is that "hello" does a literal
output of everything typed without processing the escape backslashes,
while "print hello" does process them.
Yes, and realise that
>>> hello
only works at the interactive >>> prompt. If you write a program in a
file and run it typing hello on a line by itself with have no result.
Python will quietly evaluate the string but not display it. The ability
to display a value is a debugging aid only available in the interpreter
prompt. In a program you need to explicitly call repr(hello)
This is why in my tutorial I never actually tell the users about the
hello form but always ask them to type the print... More typing but more
consistent output, so ultimately less confusion for beginners.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor