Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Oppiskele Docstring | Annotations
Mastering Python: Annotations, Errors and Environment

bookDocstring

Now, let's create the function's docstring (documentation string).

Docstring in Python is a documentation string that is used to describe the purpose and behavior of a function, module, or class. It is a string that is placed at the beginning of the function or module or class, enclosed in triple quotes """...""" and can span multiple lines:

12345
def add(a: int, b: int) -> int: """This function receives two integer arguments and returns its sum.""" return a + b print(add(21, 5))
copy

Let's look at the PyCharm hint:

How this hint looks without docstring:

The docstring is a brief description of your function.

Note

Annotations and Docstrings are used in real development. Some simple actions can save a lot of time for other developers.

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 4

Kysy tekoälyä

expand

Kysy tekoälyä

ChatGPT

Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme

Awesome!

Completion rate improved to 4.35

bookDocstring

Pyyhkäise näyttääksesi valikon

Now, let's create the function's docstring (documentation string).

Docstring in Python is a documentation string that is used to describe the purpose and behavior of a function, module, or class. It is a string that is placed at the beginning of the function or module or class, enclosed in triple quotes """...""" and can span multiple lines:

12345
def add(a: int, b: int) -> int: """This function receives two integer arguments and returns its sum.""" return a + b print(add(21, 5))
copy

Let's look at the PyCharm hint:

How this hint looks without docstring:

The docstring is a brief description of your function.

Note

Annotations and Docstrings are used in real development. Some simple actions can save a lot of time for other developers.

Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 4
some-alt