vs code symbol

What is the VS Code?

VS Code is an open-source free editor that is developed by Microsoft.  It is a lightweight editor and can run on Windows, Linux, Mac operating systems. VS Codes supports multiple programming languages like Python, Java, C++, Node.js. VS Code has a large number of extensions for different languages by which developers can code with ease. It is highly configurable which means users can change keyboard shortcuts, themes, color. Users can also manually select an interpreter if they have multiple environments.

History of VS Code:

VS Code developed by Microsoft in the year 2015. The first release was announced on April 29 in the same year. It is registered under the MIT license. As it is open-source, its source code is available in Github.

How to set the python environment in VS Code?

An environment in the context of python refers to a particular python version and some selected packages. Therefore, these packages and python focus on a certain project.

There is a “python extension” which helps vs code to search and detect a list of interpreters that are present in the hard drive. Usually, Python extension looks for a Python interpreter in the system path. If it fails to find any, it issues a warning.

If a system has multiple interpreters, then we can select any of those using  ctr+shift+P.

 

vs code editor

The picture below shows a drop-down list after triggering ctrl+shift+P

vs code inside

The picture shows a list of python interpreters that is present in the system.

The status bar shows the current interpreter

Whenever we select a Python interpreter, VS code adds an entry in the workspace setting. Because the interpreter path is a part of a workspace setting, so whenever a user opens the same workspace again, VS code automatically uses that interpreter. Thus, vs code adds an entry to python.pythonPath in the workspace setting. To reach there, press “ctrl+,”  which opens the “settings”  page.  In the search box, search ‘python.pythonPath’. “ Settings.json”  file is available under the “.vscode” folder. “.vscode” folder is located under the directory where python code resides.

 

How to run python code?

There are multiple ways to run a Python code. First and the most simple way to run is to click on the green triangle present in the top right corner of the editor.

On clicking the “green triangle”, it opens the terminal panel, and python interpreter is automatically set to the specified environment.

The picture below shows no environment selected in the terminal before running the python code.

The picture below shows, the selection of the base environment in which Python code ran. Which underlined in green color.

 

 

The second way to run the python code is to click anywhere on the editor, and select “Run Python File in Terminal”. The pic below shows that.

The third way to run the python code is to select more than one line of code. Then right-click and select “Run Selection”.

The fourth way is to use the REPL interface, in which users can enter and execute one more line at a time.  To start REPL, press ctlr+shirt+P then select “Python: Start REPL”.  Then REPL interface opens at the bottom of the editor.

vs code use

How use the log point feature of vs code?

Developers often use the print function to check the value of an expression at different stages of the code. Therefore, too many prints make the code messy.  With this intention, Log points developed. when we set a breakpoint, the editor goes into debugging mode. But in case of  Log point, code does not break rather it logs some message in the terminal. The Output(message) can be an expression or just simple text. The Log points denote by a diamond symbol. The below picture shows Logpoints are set at line number 3 and 10.

vs code logpoint related

The picture below is an example of setting a log point. “value of s”  is a simple text that will be print in the debug console and “s” inside { } will represent the value.

vs code log message

vs code debugg console

The picture above shows that the statements , the value of “c” and “s” at the line where Logpoints are set.

To summarize, the log points used to display the values of expression without writing print function.