程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

typing in the Python standard library

編輯:Python

1. What are type annotations

def test(a:int,b:str)->str:print(a)return btest(1,"abc")

As shown in the sample code above, type annotations add type descriptions by colons after parameters:

a:intmeansspecify the input parameter a as int type

b:strmeansspecify the input parameter b as str type

->strIndicates that the return value of the specified test function is srt typep>

Special note: Type annotations are only a type description for parameters, they do not enforce static type checking.

In other words, although the parameter a defines the int type, if you pass a string, the type annotation will not automatically report an error, and you may find the parameter a only in the process of subsequent code running.Type passed error.

2. Why do type annotations

As the project gets bigger and bigger, there will be more and more code. In this case, if there is no type annotation, it is easy for us to forget what the input parameter type of a method is&#


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved