How to Get Start with Python with Visual Studio Code
- 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 hello.py, and enter below content.
Python version and Which version should I use?
check 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
Multiline String in Python
a = """my test is more than one line""" print(a)
Create a function in Python
def myFunc(): return True; print(myFunc())
PIP is Python package manager, use to instal new package.
Run this command to check which versino of pip is downloaded.
Run pip list to list all the package at the system.
At pypi.org, you can find and publish Python Package.
Python can do test the code and catch the error by doing below ways.
try: print("code to test") except print("error will come to here") else print("this is interesting, no error come to here") finally print("either else and exception come here")
raise Exception("something wrong!")