Now if you want to access the documentation of a function/class/module, all you have to do is call the attribute _doc_. If you want to add a documentation of a function you can do this likeĭocstring for functions, classes, or modules is written right after their declaration before any other statement.
There are times when you have to add a full documentation about a function or a class you create or sometimes, it’s just that you have to write multi-line comments, for that we use docstring.ĭocstring is any text written under triple quotes like ”’ or “””.
Not only for other people, but it will also help you in reading your code after a long time. You can write as many comments as you would like and it’s a good practice to write comments so that others can understand your code without much hassle.
Comments are only for user understanding and are never executed with the code. They are written to describe what the code is about, it’s working what the variable stores and so on. Single Line comments start with a hashtag. These are written in a single line for example, a = "Coding Ground" #Assigns value to variable a
There are two types of comments, single-line comments which are normal comments and multi-line comments which are also known as docstrings Single Line Comments You must have noticed that in some code there is a text written beside it which describes what the code is for. Well, it is done to make your code cleaner and increase its readability. Now you might be wondering why should we even use it when we can just write it in one line. You can also put your statement under brackets for some data types and you won’t need to use backslash but it is not true for strings. To extend the statement to multiple lines, all you have to do is put a backslash ( \ ) at the end of the statement. Synta圎rror: EOL while scanning string literal Try making a multi-line statement like this one. You can extend a single statement to multiple lines. Till now, you may have only used single line statements like print(“Hello World”) but there are multi-line statements as well. Now statements can be of single-line or multi-line. Now some of you might have heard about if, else, for, while, etc… These all are statements. You assign a value to a variable, that’s a declaration/assignment statement. This is a print statement because you are printing some data, which in this case is a string.Īnything you write is a statement. StatementsĪny instruction that you give to python to execute is a statement. So, without further ado, let’s start now.