Last active
December 17, 2021 14:55
-
-
Save thuwarakeshm/2f4930629a8a88d0bb12245155d60e8f to your computer and use it in GitHub Desktop.
Python comments, why they are important?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| INSTALLED_APPS = [ | |
| "django.contrib.admin", | |
| "django.contrib.auth", | |
| "django.contrib.contenttypes", | |
| "django.contrib.sessions", | |
| "django.contrib.messages", | |
| "django.contrib.staticfiles", | |
| # Your app | |
| "myawesomeapp", | |
| ] | |
| urlpatterns = [ | |
| path('admin/', admin.site.urls), | |
| # Custom paths | |
| path('', views.home(), name='home') | |
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Planet: | |
| """A base class for all the planets.""" | |
| def orbit(self, star: str): | |
| """Orbit a star""" | |
| print(f"Orbiting {star}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import doctest | |
| def find_age(year_of_birth: int) -> int: | |
| """ | |
| Calculate age of a person | |
| >>> find_age(2010) | |
| 11 | |
| >>> find_age(2022) | |
| 0 | |
| """ | |
| return 2021 - year_of_birth | |
| print(doctest.testmod()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| solar_system_planets = [ | |
| "Mercury", | |
| "Venus", | |
| "Earth", | |
| "Mars", | |
| "Jupiter", | |
| "Saturn", | |
| "Uranus", | |
| "Neptune", | |
| ] | |
| # Print the order of every planet and the plants before and after | |
| for planet in solar_system_planets: | |
| planet_order = solar_system_planets.index(planet) + 1 | |
| print(f"{planet} is at number {planet_order} in the solar system") | |
| if planet_order > 1: | |
| print(f"{solar_system_planets[planet_order-2]} is the planet before {planet}") | |
| if planet_order < len(solar_system_planets): | |
| print(f"{solar_system_planets[planet_order]} is the planet after {planet}") | |
| print("*" * 10) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import typer | |
| def main(name: str, lastname: str = ""): | |
| """Great the user with a christmas and new year message. | |
| Args: | |
| name (str): Name of the user | |
| lastname (str, optional): The user may prefer a longer name. Defaults to "". | |
| """ | |
| typer.echo(f"Marry christmas, {name} {lastname}") | |
| if __name__ == "__main__": | |
| typer.run(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment