tags:

views:

130

answers:

2

Recently I was trying some practice programs in python and I came across this small problem.

when I typed

print ""

in IDLE, the python shell printed a null character.

If I typed

print """"""

in IDLE, the python shell printed a null character.

but the python shell is waits for an input if I type

print """"

Why is this behaviour observed. As far as my knowledge goes, it should print null character for this print """" also.

+11  A: 

In python you can have strings enclosed with either 1 or 3 quotes.

print "a"
print """a"""

In your case, the interpreter is waiting for the last triple quote.

Unknown
http://docs.python.org/reference/lexical_analysis.html#string-literals
Nathan Ross Powell
And quotes can be " or ' (but the same on each side)
odwl
+4  A: 

I suspect you mean that python printed an empty line -- this is not the same as a null character.

When you print """""", python finds an empty, triple-quoted string.

When you print """", python finds the start of a triple-quoted string, and waits for you to input the rest (ending with """).

A triple-qouted string can include other qoutes, linebreaks, etc.

gnud