How to use the interactive mode in Python.
Learn how to use the interactive mode in Python.
#more
Learn how to use the interactive mode in Python. This is a great way to test your code and play around with all the functions and variables in your file.
You can start any Python script with the -i
flag:
$ python -i my_script.py
Let's have a look at this example script:
# my_script.py
a = 5
def my_function():
print("Hello")
print("The script finished")
If we run this script with -i
, we can play around with the code afterwards. You can end the Python shell with quit()
again:
$ python -i my_script.py
The script finished
>>> a
5
>>> my_function()
Hello
>>> quit()
$
FREE VS Code / PyCharm Extensions I Use
✅ Write cleaner code with Sourcery, instant refactoring suggestions: Link*
Python Problem-Solving Bootcamp
🚀 Solve 42 programming puzzles over the course of 21 days: Link*