简体   繁体   English

我需要 ”””/”””? 他们在做什么? [重复]

[英]Do I need “”“/”“”? What do they do? [duplicate]

This question already has an answer here: 这个问题已经在这里有了答案:

One little part of my code is: 我的代码的一小部分是:

def check_bullet_alien_collisions(ai_settings, screen, ship, aliens, bullets):
    """Respond to bullet-alien collisions.""" # <-- this line
    collisions = pygame.sprite.groupcollide(bullets, aliens, False, True)
    if len(aliens) == 0:
        bullets.empty()
        create_fleet(ai_settings, screen, ship, aliens)

The second line, do I need those three sets of quotes? 第二行,我需要那三组引号吗? If so what are they used for? 如果是这样,它们是用来干什么的?

These triple quotes are used to write multiple-lines comments, like: 这些三引号用于编写多行注释,例如:

""" This variable represents collisions:
    it is used to respond to collisions
    between bullets and aliens.
"""

You can also use triple single quotes '''/''' for that. 您也可以为此使用三重单引号'''/'''。 Otherwise, you would need to write # in each comment line, like this: 否则,您需要在每个注释行中编写#,如下所示:

 # This variable represents collisions:
 # it is used to respond to collisions
 # between bullets and aliens.

In your case, since you have only one comment line, you can use the # approach instead, like this: 在您的情况下,由于只有一条注释行,因此可以改用#方法,如下所示:

# Respond to bullet-alien collisions.

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM