Code Commenting Made Simple

Makarbaderko
2 min readNov 25, 2020

--

Hey there! My name’s Makar Baderko, I’m a 12-year-old Data Scientist and today I would like to talk about comments in Python with you.

Sorry for this, but I must do it:

Subscribe to my Medium channel and stay tuned for Data Science!

„Good code is self-commented“

Types of Python comments:

In-Function First-Line Comments

Documentation comments are for anyone who will ever use your source code but are unlikely to understand or read it correctly. If you are creating a library or framework that will be used by other developers, then you will need to develop documentation for the API. The can be seen by pressing cmd + Tab after the function name when calling.

def sum(a, b):
""" This function outputs the float sum of two numbers"""
return(float(a+b))

First-line Comments

In First-Line comments, you may say some things, you usually put in the README.md file that is the main description of a repository.

"""Colour is an open-source Python package providing a comprehensive number of algorithms and datasets for colour science.It is freely available under the New BSD License terms."""Some code

What-It-Does Comments

What-Id-Does comments are usually being used to make the reader understand what does the complex mathematical formula, or really profound piece of language syntaxis do.

def hypothenuse(a, b):   #calculates hyp. using the Pythagorean theorem(a^2 + b^2 = c^2)   return(np.sqrt(a**2 + b**2))

Up here you saw basic comment types in Python3.

Thanks a lot, thumbs up! 👍

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Makarbaderko
Makarbaderko

Written by Makarbaderko

Hey there! My name's Makar Baderko, I'm 12 years old and I live in Moscow, Russia. I really love Data Science and Machine learning!

No responses yet

Write a response