The Extract Field refactoring lets you declare a new field and initialize it with the selected expression. The original expression is replaced with the usage of the field.
Extract a field in place
Position the caret within a piece of code you want to extract into a field.
Press Ctrl+Alt+F or from the main menu, select Refactor | Extract Field.
Select an expression you want to introduce as a field.
If PyCharm detects more than one occurrence in your code, it lets you specify which occurrences to replace.
If relevant, specify where the new field will be initialized - in the current method, or in a class constructor.
Specify the name of the field. Select the name from the list or type the name in the box with a red border.