On 14/01/14 07:42, Christian Alexander wrote:

Why does the interactive prompt not recognize escape sequences in
strings?  It only works correctly if I use the print function in python 3.

 >>> "Hello\nWorld"
"Hello\nWorld"

That depends on how you define "correctly"...

When you evaluate an expression at the Python prompt Python prints the repr() of the value. For strings that includes the quotes and the \n characters and any other special characters it finds. The print function on the other hand prints the str() of the value and that interprets the quotes etc out

In general repr() is more useful for debugging since it shows any 'hidden' whitespace characters. repr() by convention should return a value that can be evaluated and assigned to a variable, although it doesn't always do that for miore complex types.

hth
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to