Definition and Type of Python Comment

Categories: PHP

Python Comment is a programmer’s tool. We use them to explain the code, and the interpreter ignores them.

You never know when a programmer may have to understand code written by another and make changes to it.

Other times, give your brain a month’s time, and it might forget what it once had conjured up in your code.

For these purposes, good code will hold comments in the right places.


1. Multiline Python Comment

To have multiline python comment in your code, you must use a hash at the beginning of every line of your comment in python.

>>> #Line 1 of comment

>>> #Line 2 of comment

>>> #Line 3 of comment


This comment\nis spanned across\nmultiple lines’

This gives us an output because we type it in the shell. When you create a file and write this in that, there is no output.

While triple quotes are generally used for multiline python comment, we can conveniently use them for python comment as well.

Triple quotes will also preserve formatting.


2. Docstrings Python Comment

A docstring is a documentation string in Python. It is the first statement in a module, function, class, or method in Python. 

In this, you will learn what a python function/class does.

>>> def sayhi():


This function prints Hi


print("Hello") 

>>> sayhello()

Output

Hello

To check a function’s docstring, use its __doc__ attribute.

>>> def sayhello():


This function prints Hello


print("Hello") 

>>> sayhello.__doc__

Top articles
How to check version of php Published at:- Definition and Type of Python Comment Published at:- Pass by reference vs value Published at:- Python - Network Programming Published at:- PHP Installation on Mac OS X with Apache Published at:- PHP Installation on Windows XP 2000 and XP with IIS Published at:- PHP Installation on Windows XP 2000 & XP with Apache Published at:- PHP MCQ Quiz Question with Answer Published at:- PHP MCQ Quiz Question with Answer (set 2) Published at:- 5 Laravel Development Tools Developers Must Use Published at:- PHP and its use Published at:-
R4Rin Team
The content on R4Rin.com website is created by expert teams.