为什么python为什么使用非常规的三引号进行注释? [英] Why does python use unconventional triple-quotation marks for comments?
本文介绍了为什么python为什么使用非常规的三引号进行注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么python不仅仅使用C / C ++ / Java使用的传统注释风格?
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?
推荐答案
Python不会在注释中使用三引号。注释使用井号(aka磅):
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).
这篇关于为什么python为什么使用非常规的三引号进行注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文