Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Why didn't python just use the traditional style of comments like C/C++/Java uses:

/**
 * Comment lines 
 * More comment lines
 */

// line comments
// line comments
//

Is there a specific reason for this or is it just arbitrary?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
437 views
Welcome To Ask or Share your Answers For Others

1 Answer

Python doesn't use triple quotation marks for comments. Comments use the hash (a.k.a. pound) character:

# this is a comment

The triple quote thing is a doc string, and, unlike a comment, is actually available as a real string to the program:

>>> def bla():
...     """Print the answer"""
...     print 42
...
>>> bla.__doc__
'Print the answer'
>>> help(bla)
Help on function bla in module __main__:

bla()
    Print the answer

It's not strictly required to use triple quotes, as long as it's a string. Using """ is just a convention (and has the advantage of being multiline).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...