首页 > 解决方案 > 在 PyCharm 中对注释掉的代码使用不同的注释样式

问题描述

当使用 PyCharm 注释掉文本时(通过选择文本并点击键盘快捷键),它使用#如下普通注释:

在此处输入图像描述

我不喜欢这看起来与实际注释有多么相似(即我解释我的代码做了什么),所以它想使用不同风格的注释 ( ##) 来注释掉代码:

def execute_evil_master_plan():
    ## # Start by hijacking a government satellite.
    ## # Doesn't matter which as long as it has a death laser.
    ## satellite = hijack_government_satellite()
    ## 
    ## # aim it towards the white house and fire the laser
    ## coords = google_maps.get_coordinates(WHITE_HOUSE)
    ## satellite.aim(target=coords)
    ## satellite.fire()

有没有办法在 PyCharm 中自定义这样的评论样式?

标签: pythonpycharmcomments

解决方案


在多行注释前后使用 """。

def execute_evil_master_plan():
    """
    # Start by hijacking a government satellite.
    # Doesn't matter which as long as it has a death laser.
    satellite = hijack_government_satellite()

    # aim it towards the white house and fire the laser
    coords = google_maps.get_coordinates(WHITE_HOUSE)
    satellite.aim(target=coords)
    satellite.fire()
    """

推荐阅读