- 博客(3)
- 收藏
- 关注
原创 val = a or b
#Condition 1:a = 1b = 5c = a or bd = b or aprint(c) >>> 1print(d)>>> 5#Condition 2:a = 1b = Nonec = a or bd = b or aprint(c)>>> 1print(d)>>> 1
2021-10-09 12:04:54 73
原创 迭代中的结果拷贝
#在代码片段里,并没有修改该iteration中的局部变量curr,因此,#result.append(curr + #[root.val]) 中不需要list深拷贝def sumPathHelper(root, target, curr, result): if not root: return target -= root.val if root.left is None and root.right is None and target == 0: **result.append(cur
2021-10-06 10:43:17 80
原创 if object vs if object is None
Python代码中,判断对象是否为空,一开始很喜欢用if A,新接触的代码则发现很多人用if A is None。明明前者更简单,为什么要用后面的方式呢?if A:看如下注释,将调用自身的bool的方法,整个调用过程如下,先调用bool()操作,如果没有定义的bool(),则继续调用__len__() ,如果这两个方法都没有定义,则认为所有的实例为True除了在所有空类型情况下([],{},(),’’,0 False, and None),其它的判断都会返回Trueref:https://docs.
2021-10-06 10:00:28 188
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人