Set Up & Build Your First Python Program in VSCode

Jeff Cuartas
6 min readJul 5, 2021

In this quick tutorial, I’ll show you how to set up your local environment for Python development as well as get you started on coding your first Python program.

Python is one of the most widely used and popular programming languages. If you’re new to Python, do not fret! Depending on your background (especially if you have previous coding experience in JavaScript or Ruby), Python is easy to pick up. The simple syntax, enormous amounts of resources on the internet, and not-so-steep learning curve, makes it an ideal language for beginner developers.

Before we jump in, let’s briefly talk a bit more about what Python actually is. Python is a general-purpose programming language that supports many different programming paradigms: such as Objected Oriented Programming, Functional Programming, etc. It is widely used in scientific and specialized applications. As a full stack developer, you might also encounter Python in back-end development. Due to its power and versatility, Python is an essential tool in almost every scientific application.

I would argue that having some familiarity with Python(even if you’re just dabbling) is essential to being a well-rounded developer. And as mentioned earlier, because it’s easy to pick up, Python is a great language to play around with.

Part I: Setting up your Python Local Environment

Check your Python Version

Depending on your pc/mac, Python may already be installed on your machine. To check whether you have the latest version of Python, go ahead and open your terminal.

  • Enter the following command: <python3 -version>

If you have the latest version of python3 (3.9.6), proceed to part II of this article.

Download the Latest Version of Python

To download the latest version of Python, head over to www.python.org, go to the downloads section, and download the latest version. The Python website will auto-detect what version you will need for your machine.

Follow all the installation steps. Once this step is complete, open your terminal again, enter <python3 --version> to verify that the latest version downloaded successfully.

Part II: Using Python in VSCode

Step 1: Create a folder for your Python repository

Step 2: Open your folder in VS Code

  • I usually cd into the folder via my terminal and then enter <code .> to pull up VS Code

Step 3: Download the Python extension

  • This step is a very important: download the Python extension in VSCode. The extension will give you the best experience when working with Python files as well as offer rich support in your code editor
  • To download the extension, head over to the extension section of VSCode, type in and search for <Python> and download the first result(ms-python.python)

Step 4: Create a Python File in VSCode

  • Next, you’ll want to create your Python file
  • In order for VSCode to recognize Python files, the file name needs to end with <.py>
  • For the purposes of this tutorial, let’s name our file <program.py>

After this step is complete, your project folder in VSCode should look like this:

Part III: Python Crash Course

For our first Python program, we’re going to create a simple program that takes user input and prints out a sonnet using the data entered by the user.

Here is a rapid fire crash course into Python that will help us create this program.

Python Data Types

  • The three most common Python data types are strings, numbers, and Booleans
  • We will be working exclusively with strings in this tutorial

Variables

  • As you may know, variables are essentially containers for storing data values
  • To declare a variable in Python we simply assign a value to it
  • We can store any data type in a variable, such as a number, string, or boolean
Examples of variables in Python

How to Print

  • To print data in Python, we use the print function
  • The print function prints the specific message to the console, which can be a string or any object(which will be converted to a string)

Ok, that’s all we need to know for now. Now you’re ready to start coding!

Part IV: Basic Python Program

So in this tutorial, we’ll be building a mad libs style program using Shakespeare’s sonnet VIII as our template. The goal is to take the user input and print out a new sonnet with the entered words.

Step 1: Starter Code

Here is what our starter code should look like:

We’ll be using three print statements that are all strings.

Step 2: String Concatenation

For our mad libs program, we’ll want to modify the print statements by concatenating our strings with our users input.

String concatenation is simply a way to add strings together. The first step is to substitute a word within the string with a variable that we will concatenate into that string.

There are many ways to concatenate strings in Python. In my opinion, the easiest way to concatenate (if we’re using a variable) is to call <f > at the beginning of the string and then wrap our variable within curly braces in the string.

In this example, we’re going to use a variable named musician, another named abstract_noun, and the last one will be verb.

Step 3: Create Your Variables

Next, we will want to create our variables that are being called in our print statements.

As you can see, we created the three variables we needed for our print statements. All of the values of the variables are strings as well. However, you may notice that the data is static — in order words, if we run our program now, the information printed will match the literal values of our variables.

Instead, we would like to ask the user for their input when we run the program.

Step 4: User Input

To ask for user input, we will be using the input function within our variables.

The input function takes in a prompt message as its parameter:

Now let’s refactor our code to incorporate the input function:

Now when we run our program, the user will receive three prompts in the console that will ask for a musician, abstract noun, and a verb for our mad libs sonnet.

Step 5: Run Python Code

To run our Python code in VS Code, open your terminal and enter <python3 filename>, e.g. <python3 program.py>.

The prompts will then print to the screen. Once the input for the prompts have all been entered, the mad libs sonnet will print!

Congratulations you have created your first Python program! Keep in mind, that this is very high level tutorial designed to help get you started coding in Python.

Python is an incredibly powerful and versatile programming language and I hope this tutorial is one small but useful step of your learning journey!

Resources

--

--