Note_Tech

All technological notes.


Project maintained by simonangel-fong Hosted on GitHub Pages — Theme by mattgraham

Python Comment

back


Comments


Creating a Comment

#This is a comment
print("Hello, World!")

print("Hello, World!") #This is a comment

Multiline Comments

#This is a comment
#written in
#more than just one line
print("Hello, World!")

"""
This is a comment
written in
more than just one line
"""
print("Hello, World!")



Docstring

print("\n--------Docstring: function--------\n")


def add(x, y):
    """This function adds the values of x and y"""
    return x + y


# Displaying the docstring of the add function
print(add.__doc__)      # This function adds the values of x and y
print(help(add))
# Help on function add in module __main__:
# add(x, y)
#     This function adds the values of x and y
# None

print("\n--------Docstring: object--------\n")


class Dog:
    '''A class representing a dog'''

    def __init__(self, name, age):
        """Initialize a new dog"""
        self.name = name
        self.age = age

    def bark(self):
        """Let the dog bark"""
        print("wooof!!")


print(help(Dog))
# Help on class Dog in module __main__:

# class Dog(builtins.object)
#  |  Dog(name, age)
#  |
#  |  A class representing a dog
#  |
#  |  Methods defined here:
#  |
#  |  __init__(self, name, age)
#  |      Initialize a new dog
#  |
#  |  bark(self)
#  |      Let the dog bark
#  |
#  |  ----------------------------------------------------------------------
#  |  Data descriptors defined here:
#  |
#  |  __dict__
#  |      dictionary for instance variables (if defined)
#  |
#  |  __weakref__
#  |      list of weak references to the object (if defined)

# None


TOP