1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 【Python】函数调用外部变量

【Python】函数调用外部变量

时间:2018-11-06 11:37:01

相关推荐

【Python】函数调用外部变量

方法1

class Solution:def inorderTraversal(self, root: TreeNode) -> List[int]:res = []def help(root: TreeNode):if(root is None):return Nonehelp(root.left)res.append(root.val)help(root.right)help(root)return res

方法2

class Solution:def inorderTraversal(self, root: TreeNode) -> List[int]:global resres = []self.help(root)return resdef help(self,root):if(root is None):return Noneself.help(root.left)res.append(root.val)self.help(root.right)

猜你喜欢:👇🏻

⭐【Python】函数外定义变量并在函数内进行更新

⭐【Python】函数默认参数怎么改变?

⭐【Python】生成器有啥用?

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。