def display():
""" i am testing to see doc string """
pass
display_1=display()
print(display.__doc__)
output-:i am testing to see doc string
print(display_1.__doc__)
output-:None
def display():
""" i am testing to see doc string """
pass
display_1=display()
print(display.__doc__)
output-:i am testing to see doc string
print(display_1.__doc__)
output-:None
display_1
is not a function. It is None
as you have taken the return value of the function display()
What you want to do is this:
display_1 = display
Do not add the ()
at the end as that will call the function and store the return value in display_1
You arr calling to the function display
, which has no return. In python, if a function returns nothing explicitly, it returns None
.
So, when you are executing display_1=display()
, display_1 is None, so it has not the attribute doc
If you want to get the docstring, call display.__doc__
Look at this: Getting the docstring from a function
for example you can do like this also:
class DoubleMap(object):
def __init__(self):
self.url = "https://someurl"
def Method(self):
"""rejgnjknkjnklerg"""
return self.url
mapInstance = DoubleMap.Method.__doc__
print(mapInstance)
in your code display()
is no returning any value thats why you are getting none you can do like this if you want
def display():
""" i am testing to see doc string """
return display.__doc__
display_1=display()
print(display.__doc__)
print(display_1)