Create your first Python application

Completed

With Python and Python tools installed, you can create your first Python application! In this exercise, you'll create an empty directory, open the directory in Visual Studio Code, and then create your first application.

Step 1 - Create a directory for your code

Many projects start with an empty directory, which is how you'll start yours.

  1. Open a terminal or command window (or return to the one you had open previously).

  2. Create a new directory, and open it in Visual Studio Code by running the following command sequence:

    md hello-world
    cd hello-world
    code .
    
    mkdir hello-world
    cd hello-world
    code .
    
    mkdir hello-world
    cd hello-world
    code .
    

Step 2 - Create a new Python file and add code

With Visual Studio Code open to your empty folder, you'll now create a Python file to display the class message Hello, World.

You may see a prompt you to install Pylint, which you can install by selecting Install. If Visual Studio Code doesn't automatically detect a Python interpreter, you may be prompted select one by selecting the default option.

  1. In the Explorer view, HELLO_WORLD panel, hover over the title bar, and then select New File.

    Screenshot of the Visual Studio Code Explorer window with New File highlighted.

  2. Name the new file hello.py by entering it into the new textbox, and pressing Enter.

    Screenshot of Explorer window with hello.py entered for new file.

  3. Enter the following Python code in the editor panel. This command uses the print function to display the text Hello, World! when your application is run.

    print('Hello, World!')
    
  4. Save the file by selecting File and Save Ctrl+S.

    Screenshot of file menu with Save highlighted.

Step 3 - Run your application

Since it's a single line program, you can actually run your application from inside Visual Studio Code.

  1. Open the built-in terminal in Visual Studio Code by selecting View and Terminal.

    Screenshot of view menu with Terminal highlighted.

  2. In the new terminal window, run the following command to run your Python code.

    python hello.py
    
    python3 hello.py
    
    python3 hello.py
    

    Hello, World! appears in the terminal window. Congratulations! You've created a Python application!