Python Programming - Python Documentation

Python Programming – Python Documentation

Documentation is a very important part of any programming language. The documentation section helps in keeping track of what is a particular line of code or a block of code is performing. It includes the details such as the purpose of the program, author details, important logical aspects, and date of creation. The statements within this section are called comment lines in Python language. In Python language, we use the hash (#) symbol to start writing a comment. If extends up to the newline character. Comments are meant for programmers for a better understanding of a program. Python interpreter ignores the comment. For instance, consider code 2,4. coded in interactive mode programming i.e., directly on the Python interpreter.

Code: 2.4. Illustration of Python documentation using #

>>>str = “Hello Python”
>>> type(str)
<class ‘str’>
>>> print(str) # It will print the complete string
Hello Python
>>> str[0] # It will print the value at 0 index
‘H’
>>>str[2:5] # it will print 3<sup>rd</sup> to 5<sup>th</sup> character
llo
>>>str[2:] # it will print 3rd to the last character
llo Python
>>>str*2 #it will print the value of str twice
Hello Python Hello Python
>>>strt-” Test” # it will concatenate Test with Hello Python
Hello Python Test

Multiple Line Comment

In some situations, multiline documentation is required for a program. In other words, comments can extend to multiple lines. This can be done by using hash (#) at the beginning of each line. For instance,

# this comment is
# a multiple
# line comment

Another way is to use triple quotes either ‘ ‘ ‘ or “ “ “ for defining multiple line comments. The triple quotes include the multiple-line comments. For instance,

“ “ “ this comment is
a multiple
line comment “ “ “

Python Tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *