fertphil.blogg.se

Python comment
Python comment









Maybe you want to write some more detailed information about what we are trying to do in our code. These are single-line Python comments, we might want to do multiline comments. Now, Python comments come in a few different shapes or forms.

#Python comment code

That’s the next best use for comment in Python to comment out bits of code that we don’t want to run. We’re not going to get anything printed back because we have not got a print statement and we are simply returning the value. Well, comments allow us to print out the whole line out and now we will run this. Now when we run this, we’re actually going to get the printed value out because we are printing it inside the function.īut let’s say that we now don’t want the print function to run within the function and we want it to stop running for whatever reason, but we want to leave it handy so you can go back to it if need be. So we could say, let’s run this with some values 5 and 8. Maybe if we had a print statement just to test what was going on with the code. It is a good habit for developers to write Python comments that explain what their code is doing, as mentioned earlier comments can also be used to stop some part of the code from running. Now when someone goes back to your code, they can easily see what this function does.Īlthough this is really a simple function, imagine this was a complicated function with lots of things going on. However, we might want to put in here a comment to remind ourselves of what we did and we could use this with the hashtag symbol which says this adds x and y values together.

python comment python comment

Python comments can be used to serve different purposes when used in code, for instance, they can be used to make code more readable, or to prevent the execution of a piece of code.įor example, if we create a simple function which is called ‘add’ and we give it to numbers and it returns some of those numbers, x plus y. And whatever is written after this will be ignored by the code editor. In Python, comments are denoted with a hashtag symbol.









Python comment