In addition to regular expressions, you can also evaluate operator expressions, lambda expressions, and anonymous classes.
The following evaluation modes are available:
Expression Mode for evaluating single-line expressions.
Code Fragment Mode for evaluating short code portions. You can evaluate declarations, assignments, loops and
Besides, PyCharm provides a way to quickly evaluate an expression at caret or a selection in the editor.
While using the Expression Evaluation feature, mind the following:
A method can be invoked within the Evaluate dialog only if the debugger has stopped at a breakpoint, but has not been paused.
Expression Evaluation can only be "single-level". In other words, if PyCharm stops at a breakpoint within a method called from the Expression Evaluation, you cannot use the Expression Evaluation feature again.
Evaluating expressions using the dedicated dialog
To evaluate expressions or code fragments
- Invoke the Evaluate Expression command in one of the following ways:
If you have not selected any specific variable, just type any expression in the text field and click Evaluate.
If the specified expression cannot be evaluated, the possible reason is briefly described in the Result pane of the dialog box.
Note that you can navigate between the evaluated expressions using the list in the Expression field.
To evaluate a code fragment, click the expanding arrows in the Expression field (Shift+Enter).
The Expression field expands and changes to Code fragment. Paste the target code fragment in the text field and click Evaluate.
To navigate between the evaluated fragments, press Alt+Down and Alt+Up.
Evaluating expressions in the editor
During a debugger session, the value of any expression is shown in the tooltip every time you hover your mouse pointer over it. If an expression contains children, clicking expands the node and displays all children.
You can also use the Quick Evaluate expression functionality that lets you view the value of an expression using the keyboard only.
There are two ways to evaluate an expression quickly:
Show value tooltip on code selection
In the Debugger | Data Views settings page, enable the Show value tooltip on code selection option.
Select a code fragment with the mouse, or by pressing Ctrl+W. A tooltip with the expression value automatically appears under the selection and changes each time you change the selection.
Manually invoke the tooltip with the expression value
Place the caret at the desired location, or select an expression to be evaluated.
Choose Run | Quick Evaluate Expression on the main menu, or press Ctrl+Alt+F8. The tooltip with the expression value appears under the selected expression.