Comments in Python
Comments in Python Code
Comments in Python Code means removing some part of code from the operation without deleting it from the text area. Comments are used in every programming language to write some none coding information about what operation is performed in the below or a specific line. Let’s learn more on Comment in Python programming.
What does the Comment do in Python?
Comments are used in every programming language to remove the operability of the line of code. We can comment single line and even multiple lines in code. We use some different symbols to eliminate the operability of the piece of code. Different methods to comment on the code are:-
- #:- Used to comment on the single line of code in Python.
- ”’…..”’:- Used to comment on multiple lines in Python
- “””…..”””:- Also Used to comment on multiple lines
We can use any of the type mentioned above to comment on the python code. Not only the python code Comments are also used by programmers to make their codes readable. Commenting the code gives a clear explanation about what operation programmer want to perform in the coming line.
Using Comment lines can help you to save more time while implementing operations. For example, Initially, if we performed an operation to a program like sorting an array in ascending order. But now you want to run the same code with a sorted array in descending order. So you can comment the code for the time of not using it and again remove the comment when you want to run it in your programme.
Advantages of using Comments in Code
Some advantages of usding comments in your code are as follows:
- Makes the code readable
- Make your code easy to understand
- Saperate your functions and methords in a better way
Code for Comments in Python
#initialize a string arr = 'PrepInsta' #using step argument without start and stop #this will print the string as it is #commented the lines using single comment format print(arr) '''This will print the string in reverse order starting from the index 2 to ending point 6''' #Commented the lines using multiple line comment format ar = arr[2:7] print(ar[::-1]) """This will print the string elements with even index Starting from 2 to 7""" #Commented the lines using multiple line comment format print(arr[2:8:2])
Output: PrepInsta snIpe eIs
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment