Python Programming (138 Blogs) Become a Certified Professional
AWS Global Infrastructure

Data Science

Topics Covered
  • Business Analytics with R (32 Blogs)
  • Data Science (26 Blogs)
  • Mastering Python (92 Blogs)
  • Decision Tree Modeling Using R (1 Blogs)
SEE MORE

Python Visual Studio- Learn How To Make Your First Python Program

Last updated on Nov 27,2019 5.1K Views

8 / 62 Blog from Python Fundamentals

Python programming language is a versatile language when it comes to extending support to and from other technologies. Visual studio code is one such code editor that extends support to the python programming language using the python extension. In this article, we will learn about how we can use visual studio code for python. The following topics are covered in this session.

What Is Visual Studio Code?

The visual studio code is a lightweight yet powerful source code editor that runs on your desktop. It is available for Windows, macOS, and Linux.

It also comes with built-in support for node.js, javascript, and typescript with a wide range of external support for other languages like python, c, c++, etc.

vscode - python visual studio - edureka

Extensions

Here are some of the most popular extensions for visual studio code.

extensions - python visual studio - edureka

Now that we have a vague idea about visual studio code, let’s take a look at how we can download and install visual studio code in our systems.

Visual Studio Code Installation

You can find the relevant versions compatible with your system here.

vscode install - python visual studio - edureka

After you are finished with the installation, you can simply begin your journey for python in visual studio code.

Python Extension In Visual Studio Code

To work with python in visual studio you need to install python extension from the marketplace. It is quite easy to find the python extension in the marketplace.

python extension - python visual studio - edureka

The python extension that you need to install is named python and is published by Microsoft. Let us taka a look at a few features of python extension.

  • Intellisense

  • Linting

  • Code Formatting

  • Debugging

  • Testing

  • Jupyter Notebooks

  • Environments

  • Refactoring

After you’re done with the installation, you can start with your first python program.

Writing First Program In Visual Studio Code

To start with your first python program, go to the command prompt and type the following commands.

It will open the vs code with a hello directory, and then you can add a new file with a .py extension to write your first python program.

When you have made a new file, open the file and make a simple hello world program.

This is how we can make a simple hello world program in visual studio code using the python extension. Python extension provides many features for editing python source code in vs code.

  • Autocomplete and IntelliSense:

    They are provided for all python packages stored at standard locations, you can right click on different identifiers to take advantage of the several commands.

    • Go to Definition

    • Peek Definition

    • Go to Declaration

    • Peek Declaration

  • Run Selection/line in Terminal:

    It is used to take the selected line to the python terminal.

  • Formatting:
    It makes the code readable and easier by implementing certain rules for indents, spacing around operators, line spacing, etc.

  • Refactoring: 

    The python extensions add the following refactoring commands

    • Extract Variable – It extracts all similar occurrences of the selected text within the current scope.

    • Extract Method –  It extracts all similar occurrences of the selected expressions or block within the current scope

    • Sort Imports – Sort imports use the isort package to consolidate specific imports from the same module into a single import statement and to import statements in alphabetical order.

Now let us take a look at how we can edit an existing project using the vs code.

Editing An Existing Project

You can edit an existing project in visual studio code by simply navigating to the project in the command line, and then entering the following command.

After you enter this command, the vs code will open with the existing project on the location and you can run the project or edit the code in the visual studio code.

Now that we know how we can edit the existing projects in visual studio code, let us understand linting.

Linting

It basically highlights the syntactic and styling problems in the python source code. To enable linters we can use the following approach, although the python extension comes enabled with a pylint linter as a default. Press “ctrl+shift+p” and select the python: select linter in the pallet.

Even though linting runs automatically when you save your file. You can run linting by selecting the following in the command palette.

Following are a few specific linters:

  • Pylint –

  • Flake8

  • mypy

  • pydocstyle

  • prospector

  • Pep8

  • pylama

  • bandit

Debugging Support

Let us try to understand how debugging works in our simple hello world program.

Just click on the editor’s left gutter and set a breakpoint on the line, and press f5.

Select the configuration and it will open the debug toolbar shown below.

Press the f5 key again to run the program to completion and you will see the output in the terminal. This is how we can debug a program in visual studio code, you can see a lot of options and a debug toolbar so that you can hover over the code as well.

Now that we are done with debugging, let us understand the jupyter notebook support in visual studio code.

Jupyter Notebook Support

To open the jupyter notebook in vs code, open the command pallet and select the following

After you open the notebook, you can simply run your code and save it.

Now that we know how we can use jupyter notebook in visual studio code, let us understand how we can use the interactive python in vs code.

Interactive Python

You can simply add “#%%” in your code, and save it in a .py extension file. When you click the run cell button, it will open the python interactive panel and you can run your code directly using the python interactive window directly. Just type your code and press “ctrl+enter”.

Environments

Python extension usually looks for the environment and selects the first interpreter in the system path. To select a specific environment you can search for the environments using the command pallet.

After you select this, it will show you the available interpreters you can choose from.

This brings us to the end of this article where we have learned how we can use the visual studio code using the python extension. I hope you are clear with all that has been shared with you in this tutorial.

If you found this article on “Python Visual Studio” relevant, check out the Edureka Python Certification Training, a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe.

We are here to help you with every step on your journey and come up with a curriculum that is designed for students and professionals who want to be a Python developer. The course is designed to give you a head start into Python programming and train you for both core and advanced Python concepts along with various Python frameworks like Django.

If you come across any questions, feel free to ask all your questions in the comments section of “Python Visual Studio” and our team will be glad to answer.

Upcoming Batches For Python Certification Training Course
Course NameDate
Python Certification Training Course

Class Starts on 28th January,2023

28th January

SAT&SUN (Weekend Batch)
View Details
Python Certification Training Course

Class Starts on 25th February,2023

25th February

SAT&SUN (Weekend Batch)
View Details
Python Certification Training Course

Class Starts on 25th March,2023

25th March

SAT&SUN (Weekend Batch)
View Details
Comments
0 Comments

Join the discussion

Browse Categories

webinar REGISTER FOR FREE WEBINAR
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.

image not found!
image not found!

Python Visual Studio- Learn How To Make Your First Python Program

edureka.co