私有变量
只需要在变量名前加上 __ 两个下划线就可以了。
dict
key 是否存在
if not data.get('username'): return jsonify({'code': -1, 'msg': '缺少必要参数-username'})
|
函数注释
def f(text:str,max_len:'int>0'=80) ->str: """这个是函数的帮助说明文档,help时会显示""" return True """ 函数声明中,text:str text 是参数 :冒号后面 str是参数的注释。 如果参数有默认值,还要给注释,如下写。 max_len:'int>0'=80
->str 是函数返回值的注释。
这些注释信息都是函数的元信息,保存在f.__annotations__字典中、
需要注意,python对注释信息和f.__annotations__的一致性,不做检查 不做检查,不做强制,不做验证!什么都不做。 """
|
try except
try: ... except: import traceback traceback.print_exc() errMsg = traceback.format_exc()
|
while
for
fruits = ["apple", "banana", "cherry"] for x in fruits: print(x)
|
not None