How to Get Start with Python with Visual Studio Code

2023/3/42 min read
bookmark this
Responsive image


  • macOS, this blog's tools are tested via macOS, most of the case windows should works.
  • already installed Visual Studio Code at macOS.

Install the Python Extension via Visual Studio

At this moment this extension has around 87m download, include lots features, such as intellisense, linting, debugging and code formatting for python.

Create a Python File

create a python file as, and enter below content.


Python version and Which version should I use?

check Python version

python --version

How to download latest Python

Go to this page and download the latest version of the Python. After download the latest, restart the terminal and restart again. Python Download

How to run Python file

run this should expect to see hi as output.


Or run *python to start with Python command window, and start typing python text to verify.


Debug Python File

Unpack a Collection

With Unpack you can do below things, what scenario can be use this? you have to declare same length of variable for the collection.

numbers = [1,2,3]
x1,y1,z1 = numbers
print(x1) # 1
print(y1) # 2

Python's Build-in Data Types

  • str
  • int,float,complex
  • list,tuple,range
  • dict
  • set,frozenset
  • bool
  • bytes,bytearray,memoryview
  • NoneType

Multiline String in Python

a = """my test is
more than one line"""

Create a function in Python

def myFunc():
    return True;

What's PIP

PIP is Python package manager, use to instal new package.

Run this command to check which versino of pip is downloaded.

pip --version

Run pip list to list all the package at the system.

pip list

At, you can find and publish Python Package.

Do Try Catch like Javascript or C#

Python can do test the code and catch the error by doing below ways.

    print("code to test")
    print("error will come to here")
    print("this is interesting, no error come to here")
    print("either else and exception come here")

Throw Exception

raise Exception("something wrong!")