开一篇文章,记录关于Python有意思的用法,不断更新 1.Python树的遍历 def sum(t): tmp=0 for k in t: if not isinstance(k,list): tmp+=k else: tmp+=sum(k) return tmp if __name__=='__main__': x=[1,[2,[3,4,5,[6,7,[8,9]]]]] t=sum(x) print(t)…
Python Enum 枚举 用法汇总 import os import sys if sys.version_info.major + sys.version_info.minor * 0.1 < 3.4: from enum34 import Enum else: from enum import Enum class MyColorEnum(Enum): red = 1 red_alias = 1 blue = 2 green = 'green' MyColorEnum.red.name…