Introduce Constant
The Introduce Constant refactoring makes your source code easier to read and maintain. It also helps you avoid usage of hardcoded constants without any explanation about their values or purpose.
Introduce a constant in place
In the editor, select an expression or declaration of a variable you want to replace with a constant.
Press Ctrl+Alt+C to introduce a constant or select in the main menu.
If more than one expression is detected for the current caret position, the Expressions list appears. If this is the case, click the expression to select it. Alternatively, use the Up and Down arrow keys to navigate to the expression of interest and then press Enter to select it.

If more than one occurrence of the expression is found, specify whether you wish to replace only the selected occurrence or all the found occurrences with the new constant.

Select a name from a list that opens or type your own name and press Enter.

Extract a constant using the dialog
By default, PyCharm uses the in-place refactoring. To use the dialog for the refactoring, open the Settings dialog (Ctrl+Alt+S) , go to Editor | Code Editing, and select the In modal dialogs refactoring option in the Refactorings area.

In the editor, select an expression or declaration of a variable you want to replace with a constant.
Press Ctrl+Alt+C to introduce a constant or select in the main menu. Alternatively, right-click and choose from the context menu.
In the Extract Constant Dialog that opens, specify the name of the new constant.

To automatically replace all occurrences of the selected expression (if it is found more than once), select the option Replace all occurrences.
Click OK to create the constant.