Python Forum
what happened to these string?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what happened to these string?
#1
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?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
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
Reply
#3
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  what happened here Ricardo14 2 1,823 Apr-20-2020, 04:05 PM
Last Post: Ricardo14

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020