简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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