top of page
  • Writer's pictureMiss S

Commenting in Python

Commenting is used in programming to show what sections of the code do. They are shown in different ways, in different programming languages. In Python, they are shown using a # character. They are basically a descriptive sentence or paragraph explaining what a segment of code (or the whole program) does.


Here is an example:


Imagine we have a procedure that says ‘hello’ and the user’s name. If we needed to write a comment to describe that procedure, it could look like this:


#This function would output hello alongside the user’s name

The comment would appear just above the procedure, so it would look like this:



#This function would output hello alongside the user’s name
def welcome(name):
    print(“Hello ” + str(name))

Commenting is really important when you are writing code (or Pseudocode) because it helps whoever is reading your code understand what you are aiming to do. So don’t forget to add comments into your code from now on.

38 views0 comments

Recent Posts

See All

Computers have a brain?

An introduction to the CPU, Von Neumann architecture and the fetch-execute cycle.

Which List is Which?

This post addresses the list data structure, both those created using arrays, and linked lists.

bottom of page