Skip to content

Comments

Comments#

Comments are text annotations in code that explain what the code does. They help developers understand code without affecting how it runs.

There are two main types of comments: single-line and multi-line.

Single-Line Comments#

Single-line comments explain code on one line. They start with // in most languages or # in Python:

// This stores the opening chord of our musical composition
final var openingChord = "C Major";
// This stores the opening chord of our musical composition
val openingChord = "C Major"
// This stores the opening chord of our musical composition
const openingChord = "C Major";
// This stores the opening chord of our musical composition
const openingChord = "C Major";
// This stores the opening chord of our musical composition
let openingChord = "C Major"
# This code initialize a variable called phrase.
phrase = "I'm a phrase"

Multi-Line Comments#

Multi-line comments span multiple lines for longer explanations. They use /* */ in most languages:

/*
 * This is a multi-line comment and 
 * this code initialize a variable called phrase.
 */
final var phrase = "I'm a phrase";
/*
 * This is a multi-line comment and 
 * this code initialize a variable called phrase.
 */
val phrase = "I'm a phrase"
/*
 * This is a multi-line comment and 
 * this code initialize a variable called phrase.
 */
const phrase = "I'm a phrase";
/*
 * This is a multi-line comment and 
 * this code initialize a variable called phrase.
 */
const phrase = "I'm a phrase";
/*
 * This is a multi-line comment and 
 * this code initialize a variable called phrase.
 */
let phrase = "I'm a phrase"

Python doesn't have multi-line comments. Use multiple single-line comments instead:

# This is a multi-line comment and 
# this code initialize a variable called phrase.
phrase = "I'm a phrase"