Python Forum

Full Version: what happened to these string?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i coded this and ran it in python3:
a = """foo"""
"""bar1"""
"""bar2"""
"""bar3"""
print(a)
it ran without any exception and output just foo. what happened to the 3 "bar" strings? where did they go? to string heaven or to string hell or into a gooey tar pit?
The bar's are multiline comments. The interesting line is a = """foo""". Put a space between the first and second, and the fifth and sixth quotes and print, and you get the spaces around foo. So, in an assignment statement the """ does not designate a comment, rather it is a null string followed by foo followed by a null string. Hmm. Didn't need plus signs... Double checking on this -
a="Hello ""world"
results in Hello world
Say I do this:

def foo():
    pass
foo()
Line 3 is very familiar in Python. We do it all the time. But line 3 results in None. Where does the None go? The same place your strings went. Nowhere. Python just discards them and moves on. Lines of Python are constantly generating values, which Python just ignores.