在Python中创建多行注释的方法? [英] Way to create multiline comments in Python?
问题描述
我最近开始学习 Python ,但我找不到如何实现多行注释。大多数语言都有块注释符号,例如
I have recently started studying Python, but I couldn't find how to implement multi-line comments. Most languages have block comment symbols like
/*
*/
我在Python中试过,但它抛出一个错误,所以这可能是不正确的方式。 Python实际上有多行注释功能?
I tried this in Python, but it throws an error, so this probably is not the correct way. Does Python actually have a multiline comment feature?
推荐答案
可以使用三引号字符串。当他们不是一个docstring(类/函数/模块中的第一件事),它们被忽略。
You can use triple-quoted strings. When they're not a docstring (first thing in a class/function/module), they are ignored.
'''
This is a multiline
comment.
'''
Guido van Rossum(Python的创建者)将此推荐为专业提示。
Guido van Rossum (creator of Python) tweeted this as a "pro tip".
但是,Python的风格指南PEP8, 使用连续的单行注释,这也是您会发现在许多项目。编辑通常有一个快捷方式可以轻松地做到这一点。
However, Python's style guide, PEP8, favors using consecutive single-line comments, and this is also what you'll find in many projects. Editors usually have a shortcut to do this easily.
这篇关于在Python中创建多行注释的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!