PyCharm provides the following inline refactorings:

- The Inline Variable refactoring replaces redundant variable usage with its initializer. This refactoring is opposite to Extract Variable.

## Example

Before | After |
---|---|

import math class Solver: def demo(self): a = 3 b = 25 c = 46 return_type_of_sqrt = math.sqrt(b ** 2 - 4 * a * c) root1 = (-b + return_type_of_sqrt) / (2*a) root2 = (-b - return_type_of_sqrt) / (2*a) print(root1,root2) Solver().demo() |
import math class Solver: def demo(self): a = 3 b = 25 c = 46 root1 = (-b + math.sqrt(b**2 - 4*a*c)) / (2*a) root2 = (-b - math.sqrt(b**2 - 4*a*c)) / (2*a) print(root1,root2) Solver().demo() |

- Place the caret in the editor at the desired symbol to be inlined.
- Do one of the following:
- On the main menu or on the context menu of the selection, choose .
- Press Ctrl+Alt+NCtrl+Alt+NCtrl+Alt+NCtrl+Alt+NCtrl+Alt+NCtrl+Alt+NCtrl+Alt+NShift+Alt+IAlt ⌘ NAlt ⌘ NAlt ⌘ I.

- In the Inline dialog box that corresponds to the selected symbol, confirm the inline refactoring.