Comments in python

comments_in_python

Skill - Comments in python

Table of Contents

Skills Required

Please make sure to go through all the skills mentioned above to understand and execute the code mentioned below

Main Code

When a line in python starts with #, python will not execute the line.
So you can write any thing in a comment.

For example consider the following python code

# This is a comment which won't be executed
# Let's print Hello World!
print('Hello World!')
  • The first two lines in the above code are comments, since they start with #
  • Hence the first 2 lines will not be executed by python

Multi-line comments example are shown below. Multi-line comments are useful to write comments in more lines

"""  
This is a comment  
written in  
more than just one line  
"""
print('Hello World!')

Run this in Visual Studio Code

  • Create a folder in your PC
  • Open this folder in Visual Studio Code using menu File->Open Folder
  • Open File Explorer
  • Create a python file by any name, say hello.py and write the following
# This is a comment which won't be executed
# Let's print Hello World!
print("Hello world!")
  • Run the code using menu Run -> Run Without Debugging
  • You should see Hello world! printed in the terminal
  • Notice the the first 2 lines are not executed since they are comments

Video

Watch video on this post here

Online Interpreter

You can run these codes online at https://www.programiz.com/python-programming/online-compiler/

Further Reading

SKILL ID = XWHBZ


Table of Contents

Comments

  1. UX Python is a leading knowledge-sharing website for GUI programming and UX design using Python programming language. UX Python provides an open-source UI/UX toolkit for programmers and developers and Python Programming tutorials to create impressive digital products.
    UX Python brings tutorials such as Python For Beginners, Python Tkinter GUI Programming, Python Kivy GUI Programming, wxPython GUI Programming, PyQT5 GUI Programming, Python PyGame Programming, Python Mini Project Examples, etc.

    ReplyDelete

Post a Comment