1.2: 🚩 Comments, Keywords, and Debugging

Topic

1.2: 🚩 Comments, Keywords, and Debugging

Topic Progress:

Comments in code

So, we’ve discussed syntax and that you have to write everything in a way that the compiler will understand. But what happens when you want to write notes or break up your code into visual sections? Well, we use comments, in python, we do this by using the ‘hash’ (#) character. Whenever we put a # in a line of code, the compiler will know not to interpret it as code. See an example below for how we’ve used comments to section out our code and make it look presentable.

Example of good use of commenting

Keywords in python

Python has some reserved keywords like the one we’ve been using in our example “print()”. Keywords cannot be used as a variable or function name, keywords are also case sensitive. Keywords can do lots of different things you’ll learn more as we progress through the course.

Debugging

Debugging is a term we use in coding for finding problems in our code, usually, these are syntax errors (like indentation or bracket your missing). Most compilers hint at what the problem is, so use this to your advantage! However, sometimes it may be a bit vague to what the problem is, so that’s why we need to be precise with our programming.

In the example below, it has two errors in it and the compiler will return an error message writing in red if we run the program, which hints to where your error might be.

Your task is to debug the code to make it print “hello world”.

BEWARE OF UNBALANCED BRACKETS!!!

You’ve probably already noticed that Python uses brackets for a lot of things. Much like indentations, unbalanced brackets is a common error. Balanced brackets mean that there are as many open brackets ‘( ‘ as there are closed brackets ‘)’. Below is an example of unbalanced brackets.

print(("Coding is so easy!")

Your brackets need to be balanced for your code to work, so when debugging make sure you count your brackets!

Did you know?
Computers use to be really really big (it could take up a large room in a house, or even more!) and code used to be written physically using things like holes on pieces of paper. Occasionally bugs would crawl into these large computers and break them. Debugging referred to literally finding these bugs and removing them and the term stuck.

@

Not recently active