You need a double colon AND a blank line between the Example:: section break and the literal block.

See the example from the Napoleon docs:

"""Example Google style docstrings.

This module demonstrates documentation as specified by the `Google Python
Style Guide`_. Docstrings may extend over multiple lines. Sections are created
with a section header and a colon followed by a block of indented text.

Example:
    Examples can be given using either the ``Example`` or ``Examples``
    sections. Sections support any reStructuredText formatting, including
    literal blocks::

        $ python example_google.py

Section breaks are created by resuming unindented text. Section breaks
are also implicitly created anytime a new section starts.
"""

So, in your example, try this:

class Chicken(object):
      """Animal that lays egg and has feathers

         Note:
             Chickens love to eat feed

         Example::

             chicken.eats(feed)
      """
Answer from Brown on Stack Overflow
🌐
Readthedocs
sphinxcontrib-napoleon.readthedocs.io › en › latest › example_google.html
Example Google Style Python Docstrings — napoleon 0.7 documentation
# -*- coding: utf-8 -*- """Example Google style docstrings. This module demonstrates documentation as specified by the `Google Python Style Guide`_. Docstrings may extend over multiple lines. Sections are created with a section header and a colon followed by a block of indented text.
Top answer
1 of 2
13

You need a double colon AND a blank line between the Example:: section break and the literal block.

See the example from the Napoleon docs:

"""Example Google style docstrings.

This module demonstrates documentation as specified by the `Google Python
Style Guide`_. Docstrings may extend over multiple lines. Sections are created
with a section header and a colon followed by a block of indented text.

Example:
    Examples can be given using either the ``Example`` or ``Examples``
    sections. Sections support any reStructuredText formatting, including
    literal blocks::

        $ python example_google.py

Section breaks are created by resuming unindented text. Section breaks
are also implicitly created anytime a new section starts.
"""

So, in your example, try this:

class Chicken(object):
      """Animal that lays egg and has feathers

         Note:
             Chickens love to eat feed

         Example::

             chicken.eats(feed)
      """
2 of 2
3

Building off the answer by @Brown, it appears in order to get the Example section to render as both a recognized section break and as a code snippet you would use "Example:" followed by an indented "::" followed by a blank line and a double-indented code snippet. For me, both of the following introduce a code block beginning with a bolded "Example" in the output.

class Chicken(object):
      """Animal that lays egg and has feathers

         Note:
             Chickens love to eat feed

         Example:
             Detail about example (I'm feeding the chicken)::

                 chicken.eats(feed)
      """

OR:

class Chicken(object):
      """Animal that lays egg and has feathers

         Note:
             Chickens love to eat feed

         Example:
             ::

                 chicken.eats(feed)
      """
🌐
GitHub
gist.github.com › redlotus › 3bc387c2591e3e908c9b63b97b11d24e
Google Style Python Docstrings · GitHub
Google Style Python Docstrings. GitHub Gist: instantly share code, notes, and snippets.
🌐
Rutgers
iw3.math.rutgers.edu › solutions › example_google.html
Example Google Style Python Docstrings — Solutions 0.0.1 documentation
Docstring after attribute, with type specified. ... Class methods are similar to regular functions. ... Do not include the self parameter in the Args section. ... True if successful, False otherwise. ... list of str: Properties with both a getter and setter should only be documented in their getter method. If the setter method contains notable behavior, it should be mentioned here. exception example_google.ExampleError(msg, code)[source]
🌐
Readthedocs
gemseo.readthedocs.io › en › stable › software › example_google_docstring.html
Example Google Style Docstrings — GEMSEO 6.3.3 documentation
Sections support any reStructuredText ... literal blocks:: $ python example_google.py Section breaks are created by resuming un-indented text. Section breaks are also implicitly created anytime a new section starts. """ from __future__ import annotations from typing import TYPE_CHECKING from typing import ClassVar from typing import Final from docstring_inheritance ...
🌐
GitHub
github.com › NiklasRosenstein › pydoc-markdown › issues › 296
Google style docstring code block is not rendered correctly · Issue #296 · NiklasRosenstein/pydoc-markdown
July 7, 2023 - Using a Google-style code block retains its indentation and does not render correctly in markdown (VS Code and GitHub rendering).
Author: NiklasRosenstein
🌐
Readthedocs
gemseo.readthedocs.io › en › 5.3.2 › software › example_google_docstring.html
Example Google Style Docstrings — GEMSEO 5.3.2 documentation
Sections support any reStructuredText formatting, including literal blocks:: $ python example_google.py Section breaks are created by resuming un-indented text. Section breaks are also implicitly created anytime a new section starts. """ from __future__ import annotations from typing import TYPE_CHECKING from typing import ClassVar from typing import Final from docstring_inheritance import GoogleDocstringInheritanceMeta if TYPE_CHECKING: from collections.abc import Generator MODULE_LEVEL_VARIABLE: Final[int] = 98765 """Module level constant variable documented inline.
🌐
Readthedocs
gemseo.readthedocs.io › en › 5.3.0 › software › example_google_docstring.html
Example Google Style Docstrings — GEMSEO 5.3.0 documentation
Sections support any reStructuredText formatting, including literal blocks:: $ python example_google.py Section breaks are created by resuming un-indented text. Section breaks are also implicitly created anytime a new section starts. """ from __future__ import annotations from typing import TYPE_CHECKING from typing import ClassVar from typing import Final from docstring_inheritance import GoogleDocstringInheritanceMeta if TYPE_CHECKING: from collections.abc import Generator MODULE_LEVEL_VARIABLE: Final[int] = 98765 """Module level constant variable documented inline.
🌐
Google
google.github.io › styleguide › pyguide.html
Google Style Guides | Style guides for Google-originated open-source projects
You can update those files by running `blaze run //foo/bar:foo_test -- --update_golden_files` from the `google3` directory. """ Docstrings that do not provide any new information should not be used. ... In this section, “function” means a method, function, generator, or property. A docstring is mandatory for every function that has one or more of the following properties: ... A docstring should give enough information to write a call to the function without reading the function’s code.
Find elsewhere
🌐
Readthedocs
gemseo.readthedocs.io › en › 6.0.0 › software › example_google_docstring.html
Example Google Style Docstrings — GEMSEO 6.0.0 documentation
Sections support any reStructuredText formatting, including literal blocks:: $ python example_google.py Section breaks are created by resuming un-indented text. Section breaks are also implicitly created anytime a new section starts. """ from __future__ import annotations from typing import TYPE_CHECKING from typing import ClassVar from typing import Final from docstring_inheritance import GoogleDocstringInheritanceMeta if TYPE_CHECKING: from collections.abc import Generator MODULE_LEVEL_VARIABLE: Final[int] = 98765 """Module level constant variable documented inline.
🌐
Readthedocs
gemseo.readthedocs.io › en › 6.1.0 › software › example_google_docstring.html
Example Google Style Docstrings — GEMSEO 6.1.0 documentation
Sections support any reStructuredText ... literal blocks:: $ python example_google.py Section breaks are created by resuming un-indented text. Section breaks are also implicitly created anytime a new section starts. """ from __future__ import annotations from typing import TYPE_CHECKING from typing import ClassVar from typing import Final from docstring_inheritance ...
🌐
Medium
medium.com › jit-team › documenting-python-code-with-docstrings-b999ee164ff2
Documenting Python code with docstrings | by Adam Czapski | Jit Team | Medium
September 14, 2022 - One of the most important things to document in Python code are docstrings. Docstrings are strings that are used to document a code block, and they are typically placed at the beginning of a code block.
🌐
Readthedocs
gemseo.readthedocs.io › en › 6.3.0 › software › example_google_docstring.html
Example Google Style Docstrings — GEMSEO 6.3.0 documentation
Sections support any reStructuredText formatting, including literal blocks:: $ python example_google.py Section breaks are created by resuming un-indented text. Section breaks are also implicitly created anytime a new section starts. """ from __future__ import annotations from typing import TYPE_CHECKING from typing import ClassVar from typing import Final from docstring_inheritance import GoogleDocstringInheritanceMeta if TYPE_CHECKING: from collections.abc import Generator MODULE_LEVEL_VARIABLE: Final[int] = 98765 """Module level constant variable documented inline.
🌐
Google Workspace
workspace.google.com › marketplace › app › code_blocks › 100740430168
Code Blocks - Google Workspace Marketplace
Code Blocks makes it easy to put your code into Google Docs™. Simply select some text, click the "Format" button, and it will be formatted with the color theme of your choice.
🌐
Readthedocs
gemseo.readthedocs.io › en › 3.2.0 › software › example_google_docstring.html
Example Google Style Docstrings — GEMSEO 3.2.0 documentation
Sections support any reStructuredText formatting, including literal blocks:: $ python example_google.py Section breaks are created by resuming un-indented text. Section breaks are also implicitly created anytime a new section starts. Todo: * For module TODOs * You have to also use ``sphinx.ext.todo`` extension """ from typing import Iterable, List, Optional # noqa: F401 import six from custom_inherit import DocInheritMeta MODULE_LEVEL_VARIABLE2 = 98765 """Module level variable documented inline. The docstring may span multiple lines.
🌐
PyTorch
docs.pytorch.org › FBGEMM › general › documentation › Python.html
Adding Documentation to Python Code — FBGEMM 1.5.0 documentation
def example_method(alignment: c_size_t, param: float) -> int: """ This class is an example of how you can write docstrings. You can add multiple lines of those descriptions. Make sure to include useful information about your method. **Code Example:** .. code-block:: cpp // Here is a C++ code block std::vector<int32_t> foo(const std::vector<int32_t> &lst) { std::vector<int32_t> ret; for (const auto x : lst) { ret.emplace_back(x * 2); } return ret; } And here is a verbatim-text diagram example: ..
🌐
Sphinx
sphinx-doc.org › en › master › usage › extensions › example_google.html
Example Google Style Python Docstrings — Sphinx documentation
"""Example Google style docstrings. This module demonstrates documentation as specified by the `Google Python Style Guide`_. Docstrings may extend over multiple lines. Sections are created with a section header and a colon followed by a block of indented text.
🌐
TechRepublic
techrepublic.com › home › developer
How to Add Code to Google Docs Using Code Blocks
June 14, 2024 - Fortunately, there are plenty of tools in the Google Workspace Marketplace that will do the job. The add-on I’ve found to be the best is Code Blocks. With this extension, you can select a block of code and format it to your liking within your document.
🌐
JetBrains
jetbrains.com › pycharm › guide › tutorials › sphinx_sites › documentation
Documenting Code - JetBrains Guide
February 17, 2023 - The updated MyClass is using the Google docstring style. It also uses Python 3.6+ type hints.
🌐
Google
android.googlesource.com › platform › external › google-styleguide › + › refs › tags › android-s-beta-2 › pyguide.md
Google Python Style Guide
The docstring should be descriptive-style ("""Fetches rows from a Bigtable.""") rather than imperative-style ("""Fetch rows from a Bigtable."""), except for @property data descriptors, which should use the same style as attributes. A docstring should describe the function’s calling syntax and its semantics, not its implementation. For tricky code, comments alongside the code are more appropriate than using docstrings.