Hey, welcome to the experiments for today.
Earlier today, we needed to remove the brake lines from each to do item, and for that we tried to
different ways with first tried the list comprehension.
Which looked something like this.
So we reassigned the new client list to a.
New variable.
But then we found out that since we have this for loop, then we could simply apply the strip method
here instead of iterating over the list in a list comprehension.
So then what I did is I removed this line from the code.
Ah.
But a better way would be to just comment this line.
The way you comment a line is by using.
The hash.
Symbol.
So you just add that symbol in front of the line, you want to comment.
So what is commenting anyway?
Well, commenting means this line will not be executed by the interpreter now.
So it is in the code.
It's just for us programmers to see it, but the interpreter will not use it.
Now we get this on the line here because it is recommended to have a space between the symbol and the
command line.
It is not a requirement.
It is a recommendation.
So another illustration, if we had this print function here on top, how high and we run the codes,
of course we would see how high.
But if I add the hash symbol in front of print and and I run the code now, I will not print it out.
So comments are useful to have when you have some codes that maybe you want to execute in the future,
maybe you're not sure if you really want to delete it, so just keep it for reference there.
So the comment feature would be useful for that.
So that's one use of the comments to just comment code out so it is not executed.
The other usefulness is to describe your code.
For example.
Let's say that when you come later on in your code and you don't remember what you're doing in these
two lines.
So it's a good idea to actually when you're programming, it's a good idea to actually write a comment
here that describes these two lines.
For example, get user input and remove or and strip.
Space characters.
From it.
So by looking at this, it gives you some information about what these two lines are doing.
Similarly, you could add a comment above this line.
So you press enter here to create a break line, the hash symbol, and then you say.
Check if user action is.
And.
So that comment tells you that this case ad is checking for the user action.
However, you shouldn't abuse comments.
So I do think that in this case, this comment is unnecessary because as a programmer, you know, that
case ad checks the string against that variable.
So it doesn't really give any much extra information to just say what case ad does.
So you only need you only want to use comments when you really think it's necessary that I code the
line should have more extra information to tell to the programmer.
And that is also why variable naming is important.
So you should use meaningful names for variables so that you don't have to use comments.
For example, by saying here to dos, you know, that this is a list of to two items.
But if you just said Delta, then it would be a bit ambiguous what this would actually mean.
So be specific and descriptive with variable names.
So use comments whenever you think some code does really need some description and that's what you normally
do.
So write the line above a block of code.
For example, here would be another example.
Right to do.
In the file.
But again, this wouldn't be necessary because we know what the open function does.
But if you wanted to comment that blog, you just write the comments on top of it.
So that's about code experiments for today.
We were focused on comments and let's keep going.