Seneca

Comments

Computer Science: KS3, topic 2.3.12

Comments

Comments are lines of code that are ignored completely by the computer.

What are comments?

What are comments?

  • A comment is a line of code that is completely ignored by the computer.
  • Comments can be used to add description to your code.
  • The description makes the code easier for other people to understand.
  • Comments can also be used to leave notes and reminders to yourself.
  • Notes are useful as you work on a complex program.
How to comment

How to comment

  • To write a comment in most languages, you must use a special character.
  • The character tells the computer to ignore the rest of the line.
  • In Python, the character is a #.
Interfaces

Interfaces

  • An interface is a collection of comments which describe a subroutine.
  • An interface includes:
  • List of parameters and their types.
  • Return value and its type.
  • What the subroutine does.
Interface example

Interface example

Test yourself on Comments

  • How do you start a single-line comment in Python?

  • Pick the true sentence about comments.

  • Look at this line of Python code: # TODO: fix bug. Why can this line appear in the code without causing an error?

  • An interface is a collection of comments that describes a subroutine. How does an interface differ from a single comment on its own?

Practise this topic for free