MOCKSTACKS
EN
Questions And Answers

More Tutorials









Python Comments


Comments are used to write something which the programmer does not want to execute. Comments can be written to mark the author's name, date when the program is written, adding notes for your future self, etc.

Comments are used to make the code more understandable for the programmer.
The Interpreter does not execute comments.

There are two types of comments in Python Language -:



1. Single Line Comment
2. Multi-Line Comment

Single Line Comment:

Single Line comments are the comments which are written in a single line, i.e., they occupy the space of a single line.

  • We use # (hash/pound to write single-line comments).

  • E.g., the below program depicts the usage of comments.

  • import os
    #This is a comment
    print("Main code started")
    
    #Now I will write my code here:
    print(os.listdir())

    Multi-Line Comment:

    Multi-Line comments are the comments which are created by using multiple lines, i.e., they occupy more than one line in a program.

    We use ' ' '….. Comment ….' ' ' for writing multi-line comments in Python (Use lines enclosed with three quotes for writing multi-line comments). An example of a multi-line comment is shown below:
    import os
    '''This is a comment
    Author: Harry
    Date: 27 November 2020
    Multi-line comment ends here
    '''
    print("Main code started")
    
    #Now I will write my code here:
    print(os.listdir())


    Conclusion

    In this page (written and validated by ) you learned about Python Comments . What's Next? If you are interested in completing Python tutorial, your next topic will be learning about: Python Print Statement.



    Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


    Share On:


    Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.