This is due to the default line length for black being longer than you'd like – 88 characters per line.

To decrease the line length, you can use the --line-length flag as documented here:

https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html

For example:

$ black --line-length 80 example.py

Black explains the --line-length setting in more detail here:

https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length

Line length

You probably noticed the peculiar default line length. Black defaults to 88 characters per line, which happens to be 10% over 80. This number was found to produce significantly shorter files than sticking with 80 (the most popular), or even 79 (used by the standard library). In general, 90-ish seems like the wise choice.

If you're paid by the line of code you write, you can pass --line-length with a lower number. Black will try to respect that. However, sometimes it won't be able to without breaking other rules. In those rare cases, auto-formatted code will exceed your allotted limit.

You can also increase it, but remember that people with sight disabilities find it harder to work with line lengths exceeding 100 characters. It also adversely affects side-by-side diff review on typical screen resolutions. Long lines also make it harder to present code neatly in documentation or talk slides.

Emphasis on the final paragraph.

I'd recommend just keeping the default settings. The beauty of Black is that it chooses for you, and therefor preempts any arguments about which way is "best".

Answer from damon on Stack Overflow
🌐
Read the Docs
black.readthedocs.io › en › stable › usage_and_configuration › the_basics.html
The basics - Black 26.3.1 documentation - Black Code Formatter
Show available command-line options and exit. Format the code passed in as a string. $ black --code "print ( 'hello, world' )" print("hello, world") How many characters per line to allow. The default is 88. See also the style documentation. Python versions that should be supported by Black’s output.
🌐
GitHub
github.com › psf › black
GitHub - psf/black: The uncompromising Python code formatter · GitHub
Black makes code review faster by producing the smallest diffs possible. Watch the PyCon 2019 talk to learn more. Read the documentation on ReadTheDocs! Black can be installed by running pip install black. It requires Python 3.10+ to run.
Starred by 41.5K users
Forked by 2.8K users
Languages   Python
Discussions

code formatting - In Python, how to tweak Black formatter, if possible? - Stack Overflow
I know that Black is an opinionated formatter, but I love everything it does except one major thing. When I have a function with multiple arguments, instead of displaying it like this: def More on stackoverflow.com
🌐 stackoverflow.com
Python Black Formatter
[[language]] name = "python" auto-format = false [language.formatter] command = "black" args = [ "-", # stdin "--quiet", "--line-length=79", ] More on reddit.com
🌐 r/HelixEditor
6
8
September 29, 2022
python - Black formatter - Ignore specific multi-line code - Stack Overflow
I would like to ignore a specific multi-line code by black python formatter. Particularly, this is used for np.array or matrix construction which turned ugly when formatted. Below is the example. np. More on stackoverflow.com
🌐 stackoverflow.com
sabse common Python linter, formatter?
🌐 r/Python
🌐
PyPI
pypi.org › project › black
black · PyPI
Black makes code review faster by producing the smallest diffs possible. Watch the PyCon 2019 talk to learn more. Read the documentation on ReadTheDocs! Black can be installed by running pip install black. It requires Python 3.10+ to run.
      » pip install black
    
Published   Mar 12, 2026
Version   26.3.1
🌐
freeCodeCamp
freecodecamp.org › news › auto-format-your-python-code-with-black
How to Auto-Format Your Python Code with Black
September 4, 2024 - The Python code is now formatted and it’s more readable. To format more than one python file, write black folder_name/ in the terminal. ... Three python files within the folder named python_with_black have been reformatted.
Top answer
1 of 7
112

This is due to the default line length for black being longer than you'd like – 88 characters per line.

To decrease the line length, you can use the --line-length flag as documented here:

https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html

For example:

$ black --line-length 80 example.py

Black explains the --line-length setting in more detail here:

https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length

Line length

You probably noticed the peculiar default line length. Black defaults to 88 characters per line, which happens to be 10% over 80. This number was found to produce significantly shorter files than sticking with 80 (the most popular), or even 79 (used by the standard library). In general, 90-ish seems like the wise choice.

If you're paid by the line of code you write, you can pass --line-length with a lower number. Black will try to respect that. However, sometimes it won't be able to without breaking other rules. In those rare cases, auto-formatted code will exceed your allotted limit.

You can also increase it, but remember that people with sight disabilities find it harder to work with line lengths exceeding 100 characters. It also adversely affects side-by-side diff review on typical screen resolutions. Long lines also make it harder to present code neatly in documentation or talk slides.

Emphasis on the final paragraph.

I'd recommend just keeping the default settings. The beauty of Black is that it chooses for you, and therefor preempts any arguments about which way is "best".

2 of 7
72

This is now possible by adding a trailing comma to your last argument.

In your example you would write instead:

def example_function(
    arg_1: str, 
    arg_2: bool, 
    arg_3: int = 0, 
    arg_4: int = 1, 
    arg_5: float = 0.0, # <-- Notice the trailing comma
):
🌐
Visual Studio Code
code.visualstudio.com › docs › python › formatting
Formatting Python in VS Code
November 3, 2021 - Alternatively, you can set it as the default formatter for all Python files by setting "editor.defaultFormatter" in your User settings.json file, under a [python] scope. You can open settings.json with the Preferences: Open User Settings (JSON) command. For example, to set Black Formatter as the default formatter, add the following setting to your User settings.json file: "[python]": { "editor.defaultFormatter": "ms-python.black-formatter" } In order to set a formatter extension as an import sorter, you can set your preference under "editor.codeActionsOnSave" in your User settings.json file or your Workspace settings.json file, under a [python] scope.
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Black Formatter - Visual Studio Marketplace
Extension for Visual Studio Code - Formatting support for Python files using the Black formatter.
Find elsewhere
🌐
Read the Docs
black.readthedocs.io › en › stable › the_black_code_style › current_style.html
The Black code style - Black 26.3.1 documentation
See AST before and after formatting for more discussion. Black will add trailing commas to expressions that are split by comma where each element is on its own line. This includes function signatures. One exception to adding trailing commas is function signatures containing *, *args, or **kwargs. In this case a trailing comma is only safe to use on Python ...
🌐
StatusNeo
statusneo.com › home › software development › introducing black: the uncompromising python code formatter
Introducing Black: The Uncompromising Python Code Formatter - StatusNeo
October 23, 2023 - After running the command, Black will automatically reformat the code according to its predefined rules: ... As we can see, Black has reformatted the code by removing unnecessary spaces, adjusting the indentation, and applying other formatting rules to produce clean and Pythonic code.
🌐
Black
black.readthedocs.io
Black 26.3.1 documentation
Black makes code review faster by producing the smallest diffs possible. Blackened code looks the same regardless of the project you’re reading. Formatting becomes transparent after a while and you can focus on the content instead.
🌐
GeeksforGeeks
geeksforgeeks.org › python-code-formatting-using-black
Python code formatting using Black - GeeksforGeeks
August 5, 2021 - After creating this file run the below command. ... 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 if __name__ == "__main__": print(is_unique(input())) In the above example, both are the same piece code but after using black it is formatted and thus easy to understand.
🌐
Vercel
black.vercel.app
Black Playground
Playground for Black, the uncompromising Python code formatter.
🌐
Read the Docs
black.readthedocs.io › en › stable › integrations › editors.html
Editor integration - Black 26.3.1 documentation
hook global WinSetOption filetype=python %{ set-option window formatcmd 'black -q -' } Use Thonny-black-formatter.
🌐
PyDevTools
pydevtools.com › handbook › reference › black
Black: Python Code Formatter | pydevtools
1 day ago - Black transforms code with a focus on consistency and correctness. It formats code the same way regardless of its original style while preserving the code’s semantics. The formatter handles complex Python constructs correctly and maintains ...
🌐
Medium
medium.com › analytics-vidhya › auto-format-your-python-code-with-black-f74d5f13bd7c
Auto Format your Python Code with Black. | by Davis David | Analytics Vidhya | Medium
February 22, 2024 - First make sure you have installed jupyter-contrib-nbextensions and black, then run the following commands. jupyter nbextension install https://github.com/drillan/jupyter-black/archive/master.zip — user · Then enable the extension by running. jupyter nbextension enable jupyter-black-master/jupyter-black · Now you can start formatting your python code in each notebook cell.
🌐
Invent with Python
inventwithpython.com › beyond › chapter3.html
Chapter 3 - Code Formatting with Black
December 7, 2020 - You can also use the -l line length limit and -S options in the same command: C:\Users\Al>python –m black –l 120 -S yourScript.py · Although Black won’t rename your variable or change your program’s behavior, you might not like the style changes Black makes.
🌐
Hexmos
hexmos.com › freedevtools › c › security › black
Black Formatter - Python Code Formatting Tool Cheatsheet | security Reference | Online Free DevTools
It automatically formats your Python code according to its strict rules, ensuring uniformity. This includes aspects like line length, indentation, spacing, and import ordering. You can integrate Black into your development workflow in several ways. It can be run manually from the command line, as part of a pre-commit hook, or within your CI/CD pipeline.
🌐
Medium
lewoudar.medium.com › black-and-blues-a5e92e047487
Black and Blues. Formatting tools for python | by Kevin Tewouda | Medium
March 27, 2023 - The usage is not different from black since it is based on the latter. # to apply it on a directory and subdirectories $ blue . # to apply it on a file $ blue formatting.py # to only show the differences like Git does $ blue formatting.py --diff