Printing HTML

May 16, 2005 23:47

I'm so pleased this community has been resurrected. To start the ball rolling:

curiosity about printing HTML )

Leave a comment

isabeau May 16 2005, 23:43:41 UTC
"foo" and """foo""" are in many respects the same thing; they're both strings. A string on a line by itself is an implicit print command, basically, although I often see print used with the single-quote version and not with the triple-quote version.

The "foo" version doesn't allow you to have quotes -- you can do print "foo"+otherstuff+"bar";, which means that if you want to print quotes within the string, you either need to escape it by using \" instead of " (some sample text), or need to use single-quotes, which don't count as the end-of-string marker ((some sample text)

I'm not sure whether the single-quote version allows newlines -- that is, I know a triple-quote version can start on one line and end fifty lines later; I don't know if a single-quote version can do that or not.

The primary advantage, at least to my mind, of the triple-quote version is that you don't need to escape the quotes. (Especially since I've trained myself into -format HTML tags, and retraining myself to either use ' or \" is annoying.) I'll also often use single quotes for short stretches of code and triple quotes for longer stretches.

Reply

lithiana May 17 2005, 00:49:34 UTC
I'm not sure whether the single-quote version allows newlines -- that is, I know a triple-quote version can start on one line and end fifty lines later; I don't know if a single-quote version can do that or not.

i'm sure i read somewhere that you couldn't do this with single quotes, but i just tried it, and you can. so who knows...

Reply

isabeau May 17 2005, 01:27:57 UTC
(and yes I am a dork and forgot a tag somewhere in there but I'm too lazy to repost.)

Reply

88888888 May 18 2005, 21:37:18 UTC
I definitely can't remember to escape my single-quotes, so I always go ahead and use triple-quotes under the assumption that I'll end up with a single-quote in there somewhere and will throw things when the compiler yells at me for it.

Reply


Leave a comment

Up