Comments and Doc Strings¶
Let us understand how we can add comments in Python. We will also see how doc strings are specified in Python.
Typically comments start with #
We need to start a comment with # always in each line.
We also use doc strings to provide instructions to use a function.
Doc strings are provided immediately after function name. We can specify it as standard Python string.
People typically enclose doc string with in 3 quotes (single or double). However, we can use one quote as well.
print('Hello World')
Hello World
print("Hello World")
Hello World
print("Hello World from 'itversity'")
Hello World from 'itversity'
print('Hello World from "itversity"')
Hello World from "itversity"
print("""Hello World from 'itversity'""")
Hello World from 'itversity'
print("""Hello World from "itversity" """)
Hello World from "itversity"
var1 = 'World'
var2 = 'itversity'
print(f'Hello {var1} from {var2}')
Hello World from itversity
print(f'Hello {var1} from {var2}'.format(var1='world', var2='itversity'))
Hello World from itversity