Black-formatter Example

Note: View the source of this document along with unformatted python codes by clicking </> Code on top-right corner to compare.

Example 1

print("hello, world")
hello, world

Example 2

def is_unique(s):
    s = list(s)
    s.sort()

    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            return 0
    else:
        return 1

black defaults to 88 character per line. But you can change this default behavior by specifying line-length in the pyproject.toml file.

pyproject.toml
[tool.black]
line-length = 40

Example 3

This extension works on non executable code blocks (i.e. {.python}) too.

def example_function(
    arg_1: str,
    arg_2: bool,
    arg_3: int = 0,
    arg_4: int = 1,
    arg_5: float = 0.0,
):
    pass

Example 4

def function(
    name,
    default=None,
    *args,
    variable="1123",
    a,
    b,
    c,
    employee,
    office,
    d,
    e,
    f,
    **kwargs
):
    """This is function is created to demonstrate black"""
    pass