• Miss 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.

25 views0 comments

Recent Posts

See All

Malicious Software

Malicious software is a method of performing a cybersecurity attack, and uses software that has malicious (meaning bad) intentions to undertake the attack. It is another term often heard when discussi

Social Engineering

Social engineering is a term that covers many hacking methods, and is a term often seen in the Cybersecurity landscape. In social engineering, the attacks rely on the person as a weakness, rather than

Introduction to Cybersecurity

Cybersecurity is the practice of protecting ourselves and our digital information from theft, hardware from damage and servers from misuse.