Using the _ Operator to Reference the Last Result in Interactive Mode
In Python, when working in an interactive shell (such as REPL or Jupyter Notebook), you can use the underscore symbol _ to access the result of the last expression. This simplifies working with calculations when you need to quickly use the previous result.
Using the _ operator in the interactive shell speeds up access to previous results and makes working with calculations more convenient and faster.
# Calculate the result of a complex expression
result = 5 + 10
print(result) # 15
# Now we can use the result via _ for the next calculation
new_result = _ * 2
print(new_result) # 30
Page of .
Leave a comment
You must be logged in to leave a comment.
Log in or
sign up to join the discussion.
Comments (0)