Start learning free

LESSON 3 OF 671 · WELCOME TO GO

Comments in Go

Lesson

TL ; DR:

  • Comments are lines of code that Go intentionally ignores. They are notes for humans.


  • You add a single-line comment in Go by typing // followed by text:

    // This is a comment
    fmt.Println("This is not a comment")
    


Full lesson:

Comments help explain what code does without changing what the program runs.

Go supports single-line comments:

// Next line will greet the user:
fmt.Println("Hello user!")

Go also supports multi-line comments:

/* This is a
multi-line comment */

fmt.Println("Hello user!")

Assignment
Follow the Coding Tutorial and let's write a comment!


Hint
Use // for a single-line comment.


STEP 1 OF 1
    Ctrl + Enter to check