Best 5 way to run python code in vscode

 


Visual studio code is free IDLE for any programming language. it's a lightweight but powerful source code that runs on your desktop and it avails all kinds of operating systems like Windows, MAC, and Linux.

VS code is a big library base IDLE, Sometimes code is stuck because specific extensions are not running well. I think you are also facing these kinds of problems on a daily basis if you are using vs code. 

for this kind of problem, we need to know another way to run our program 

so here are the best 5 ways to run the program in vs code...

See Also :

1. Using a built-in python extension

open your python file or create a python file using .py (test.py)

using "F5"  or going to the run menu and selecting "start dubbing" to run your code in dubbing mode.

you can use the "run python file in terminal " in the command palette (ctrl + shift + p) to run your code without debugging

2. Using an integrated terminal 

  • open a terminal window by pressing  ctrl+  
  • navigate to the directory that contains your python file using the cd command
  • run your python file using the command " test.py".

3. Using code runner extension

open your python file or create a python file in vs code
Press  " ctrl + Alt + n "

4. Using python REPL

open the command palette (ctrl + shift +p ) and type "Python: start REPL" to lunch the python REPL
type your python code into REPL and press enter and execute it
example:
PS D:\IT\Data_Analyst\2.1.  python\practice set> & C:/Users/Dileep/AppData/Local/Programs/Python/Python310/python.exe
Python 3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> numbers=[1,2,3]
>>> print(numbers)
[1, 2, 3]

5. Using the task runner

open the command palette ( ctrl+shift+p ) and select " tasks: Configure Task" to create a new task
select create tasks.json file from the template and choose the appropriate templates for your task
define your task by specifying the command to run your python code
Press " ctrl+shift+B " to run your task

example: you can create a task that runs your Python script by adding the following configuration to your tasks.json file
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Run Python Script",
            "type": "shell",
            "command": "python my_script.py",
            "presentation": {
                "reveal": "always",
                "panel": "new"
            }
        }
    ]
}

after creating this task you can run it by pressing  " ctrl+shift+b " and selecting run python script from the list of tasks.