Skip to content

Lab 02 - Using the Python Interpreter

This is an introductory lab that shows how to access the Python Interpreter on the command line.

Task 1 - Start the Python Interpreter

Step 1-1

Connect to the course Linux Jump Host virtual machine using either RDP or SSH.

Step 1-2 (Only if you chose to use RDP)

While in the course virtual machine, click the Terminal icon on the desktop.

Step 1-3

Type in the word python and press Enter.

You will see the following prompt:

ntc@ntc-training:~$ python
Python 3.8.12 (default, Oct 13 2021, 09:22:51)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

When you see the ntc@ntc-training:~$ at the command line prompt, this should tell you that you're at a "Linux shell" (or bash) prompt. When you see the >>>, you now know that you're at an interactive Python prompt using the native Python Interpreter.

Step 1-4

Once you're in the shell, type print("Hello World!")

>>> print("Hello World!")
Hello World!

This means you are now in the Python Interpreter and can immediately start programming in Python. Since Python is an interpreted language, there is no requirement to create a complete program in a file before the code is executed. You can just start programming.

Conclusion

This was just a short mini-lab to understand how to access the Python Interpreter.

Note that modern network operating systems such as Cisco NX-OS and Arista EOS also have a Python execution engine, e.g. Python Interpreter on each switch. If you SSH into a switch that supports Python, you'll be able to access a "shell" environment on the switch by also just typing "python".

The next several labs will use the Python Interpreter (shell) to start conveying critical Python concepts to be aware of when starting a journey on network automation.