0

I was reading the Django documentation, and I came across this code:

from django.db import models

class Person(models.Model):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    birth_date = models.DateField()

    def baby_boomer_status(self):
        "Returns the person's baby-boomer status."
        import datetime
        if self.birth_date < datetime.date(1945, 8, 1):
            return "Pre-boomer"
        elif self.birth_date < datetime.date(1965, 1, 1):
            return "Baby boomer"
        else:
            return "Post-boomer"

What is the purpose of putting a string below a function definition i.e baby_boomer_status()?

1 Answers1

2

That is called the docstring. Is not only for code commenting, but also can be accessed from the .__doc__ method to check info about the funcion:

enter image description here

TitoOrt
  • 1,265
  • 1
  • 11
  • 13
  • thanks for your answer but the examples you provided in your answer used explicit comments. On the other hand, the example I gave uses a string. Is there a difference? – sakhimpungose May 12 '20 at 10:16