hackshoogl.blogg.se

Python comment
Python comment













python comment

This article covers the basics of writing comments in Python. Do not explain something that is obvious to the reader.

PYTHON COMMENT CODE

The comments also help other developers to understand your code and its purpose.Ĭomments should be short and to the point. The chances are that you will not remember why you wrote some complicated piece of code unless you added a comment. Let’s say you want to change a script that you wrote a few months or years ago. To have a multi-line comment in Python, we use triple single quotes at the beginning and at the end of the comment, as shown below.

python comment

For example, if you wrote a complex regex, you add a comment describing what the code does.Īdding comments to your Python code will save you a lot of time and effort when you look at your code in the future. A comment is a human-readable explanation or annotation that is used to explain the code. The type comments are just comments, so they can be used in any version of Python. For variables, add the type comment on the same line: myvariable 42 type: int. Having long strings of hashes may seem to make the comments easier to read, but they can be annoying to deal with when comments change Take advantage of language features that provide 'auto documentation', i.e. Python has two ways to comment out a block of code: The hashtag symbol tells the Python interpreter to ignore the rest of the line.

python comment

Organizing the code, giving variables and functions descriptive names are several ways to do this.Īnother way to improve the readability of your code is to use comments. In Python, comments are added after, if it is a single line comment and triple quotes() for more than one line comment. To add type comments to a function, you do this: def func(arg): type: (str) -> str. When writing Python code, it is always a good practice to make your code clean and easily understandable.















Python comment