Skip to content

Inline Variable

Documentation Index

Fetch the complete documentation index at: https://docs.sourcery.ai/llms.txt

Use this file to discover all available pages before exploring further.

Inline variable that is only used once

thelist = []
for i in range(10):
k = i**2
thelist.append(k)
thelist = []
for i in range(10):
thelist.append(i**2)

Inlining variable can help to streamline the code, but can also make it less readable. Sourcery will only inline variables where doing so allows further readability changes to be made, such as converting a loop into a list comprehension.