Learning the Very Basics of Python

In this Learning Lab you will learn the basics of Python syntax, scope, variables, operators and simple conditional statements


Completion Time: 45 minutes

  • Understand basic Python indentation and scope
  • Learn how to assign and use variables
  • Use the Python assignment and comparison operators
  • Apply Python conditional statements



  • To run the code samples, you need to have Python 3 installed on your machine.
  • If you are working on a DevNet Learning Lab PC at a DevNet event, Python 3.x + is already installed.
  • See How to Set up Your Own Computer section above for how to install Python on your own machine.

Clone Git Repo

  • If you are working on a DevNet Learning Lab PC at a DevNet event,
    • Open the Git Command window by clicking on the Git CMD icon on the Task Bar or click on the Start button, then in the Run bar type: git cmd and press the Enter key.
  • If you are working from your own workstation, on your desktop open a command terminal.
  • Go to the root directory by typing: cd /
  • Create a directory called 'C:\DevNetCode\yourname' by typing: mkdir DevNetCode/<your-name>
    • For example: mkdir DevNetCode/brTiller
  • Go to the new directory by typing: cd /DevNetCode/<your-name>
    • For example: cd /DevNetCode/brTiller
  • Clone the devnet-express-code-samples repository from GitHub. Enter the command below.
    git clone https://github.com/CiscoDevNet/devnet-express-code-samples

    Inside the directory you created you should now see directory 'devnet-express-code-samples'. You can also see the list of files by typing ls in the console.

Step 1. Python Version and Interpreter

Checking Your Python Version

It's quite easy to check the version of Python installed on your system. For example, in the Windows Operating System simply access a terminal window, then at the command prompt type: python -V and press the return key. If you have multiple versions of python installed on your system or python 3 you may need to type either py -3 -V or python3 -V depending upon your operating system. See the graphic below for details.

Here's an example of how to get the Python version.

Using the Python Interpreter

At the command prompt you can enter the Python Interpreter by simply typing python in Windows and pressing the return key. Inside the Interpreter you can write and run very basic Python code. To exit type Ctrl + z or quit().

Here's an example of using the Python interpreter

Give it a try!

Get the Python Version.

  1. Open a terminal
  2. Enter the appropriate python command for your operating system to get the version. For example, in Windows you would type python -V then press the return key.

Use the Python Interpreter

  1. Type the appropriate python command to start the interpreter. For example, in Windows you would type python then press the return key.
  2. Type print("Hello World! How are you?") and press the return key.
  3. When you are done, to exit the interpreter press the Ctrl key then z or enter quit()

Next Step: Learn about and how to run Python scripts