Skip to main content

Giving comments in python

What are Comments ?

Comments are some statements or some expressions that we write for enhancing the readability of our code and making our program easier to understand. Python interpreter just simply ignore these comments and they doesn't become the part of program. We can simply say that we write them for simplicity and clarity of code.So that we face no problem in understanding them in future and comments also help other people to easily understand your code.

How to give comments in python?

There are basically two types of comments :-
1) Single Line Comment
    These are the comments which we give in a single line.
    These can   be given by simply given by writing : 
    #  followed by the statement that you want to give

eg.  # I am a comment and python interpreter will definitely  ignore me 

eg. print("This is the comments tutorial")
      # I am a print statement  and this line will not affect your code

2) Multi Line Comment
     If we want to give comments in multiple lines then instead
     of using # in every line we can use  '''  '''     or  """ """   
     
 eg. ''' I am also a type of comment you can use me also .If 
            you got bored of using # then you can use me also '''



eg. # This is a comment 
      # given in more than 
      # one line
      print("We are giving single line comments.")

         '''  This is a comment 
       given in more than 
       one line '''
      print("We are giving multi line comments.")


    Output:   We are giving single line comments.
                    We are giving multi line comments.



Comments

Popular posts from this blog

How to install python IDE ? IDLE and Pycharm

How to install Python IDE on Windows 10(Pycharm and IDLE)? Pycharm is the best Python IDE available.It comes with many in -built features. We will discuss its shortcuts in our next blogs.Pycharm is a cross-platform editor developed by jetbrains.   Installing Python Step 1) Visit the official website of python or click the below link              https://www.python.org/downloads/  .  Step 2) Click on Download Python               Step 3) After the download is complete ,open the exe file and click               on Install now  Step 4) After the successful installation it will show you a message         Setup was successful Step 5) Now go to your windows search bar and type "IDLE"              Press Enter and you will see that idle is opened Installing Pycharm St...

String Slicing in python

String Slicing Python  Slicing refers to extracting some words from a string. As in many other languages there are many different concepts for extracting a letters or words from a string ,in python we are having the concept of slicing. We can also the same things using looping, we will learn about it in our next tutorials. Indexing in Strings Before starting slicing, we need to understand the indexing in python. We have the concept of positive indexing  and  negative indexing.  Positive indexing starts from 0 to (length of string).It goes from forward to backward. Negative indexing starts from -1 to -(length of string + 1). It is illustrated in below example Below are some examples of how to use string slicing to extract characters from string. Accessing the characters in a string using positive index eg. string= "We are studying string slicing" s=string[ 0 ] # A single character will be printed present at index 0 w=string[ 4 ] # A...