How to add code comments in Python in Vscode

foreword

As a full-time engineer, I have learned Java, C#, JS. In fact, language is everything, especially from static language to dynamic language. The difference between a static language and a dynamic language is: whether attributes can change. Static language is suitable for writing complex functions, and dynamic language is suitable for writing simple functions. Of course, this is only relatively speaking, as long as your code management is good, it is actually the same. If you want to say the difference, the static language will be more efficient.

In fact, as long as you have been exposed to JS, you can get started with Python very quickly, but I am still not used to using Python directly without naming. I feel that it is easy to make bugs if you write too much, and you need to be aware of scope and code naming in dynamic languages. Extremely high sensitivity, otherwise Debug will be very tortured later.

Too much nonsense, let’s talk about how to set code hints

code hints

Realize the effect:

Can describe the type of the parameter and
insert image description here

Python comes with code annotation

Python functions have their own category annotations, but they are only syntax support, but not strictly tested. Even if you mark the string, you can still run it by entering the numeric code.

# 符号:后面的是参数的类别标注,符号->的是返回值的类别标注
def MyFunction(value1:str,value2:int,value3: bool)-> bool:
    print(value1,value2,value3)

insert image description here

insert image description here
Tips: Annotations are just comments and do not affect the running of the code. and can only enter the attribute type

Crooked move, default parameters

Python functions can achieve functions similar to overloading by setting the initial value

# 添加默认参数
def Myfunction(name=1,age=1):
    print(name,age)

insert image description here

vscode code annotation

Trigger condition, enter the symbol three times in Vscode in a row"
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/qq_44695769/article/details/131659152