Menu
Coddy logo textTech

Inline Comments

Lesson 7 of 28 in Coddy's Clean Code - Write better code using Python course.

Inline comments explain a single statement in a piece of code.

  • Write inline comments on the same line as the statement they refer to.
  • Separate inline comments by two or more spaces from the statement.
  • Starts with a # and a single space.
  • Don’t use them to explain the obvious.

For example,

result = check(name)  # Check if name is good

Most of the times you will prefer using Comments Blocks instead of Inline Blocks.

challenge icon

Challenge

Easy

You are given small code which makes small calculation to increase the salary, write an inline comment which explains this line.

This is probably an obvious explanation but for the sake of our practice we will do it...

Try it yourself

salary = 1000
salary = salary * 1.05

All lessons in Clean Code - Write better code using Python