python code practice(四):树、图 1、平衡二叉树 给定一个二叉树,判断它是否是高度平衡的二叉树。 本题中,一棵高度平衡二叉树定义为: 一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过1。 示例1: 给定二叉树 [3,9,20,null,null,15,7] 3 / \ 9 20 / \ 15 7 返回true 。 示例2: 给定...
defmatch(self, s, pattern):#write code here#如果两者都为空,则匹配成功if(len(s) == 0andlen(pattern) ==0):returnTrue#如果模式为空,字符串不为空,则匹配不成功if(len(s) > 0andlen(pattern) ==0):returnFalseiflen(pattern) > 1andpattern[1] =='*':ifsand(pattern[0] =='.'ors[0] ...
Numpy Interview Questions 1. How will you reverse the numpy array using one line of code? This can be done as shown in the following: reversed_array = arr[::-1] where arr = original given array, reverse_array is the resultant after reversing all elements in the input. 2. How will ...
These are not the only concepts you should know, of course. But it should give you a sound basis for interview preparation and answering somemore python interview questions. To practice more Python Pandas functions, check out our post “Python Pandas Interview Questions for Data Science” that w...
Virtual environments are a great Python feature that allows you to create separate environments for running different Python code on the same machine. In practice, a virtual environment is just a directory tree that contains a Python installation and some other additional packages. Think of a ty...
Here are 24 questions focusing on the Python del instruction within the context of lists for the PCEP-30-02 certification exam. The questions are presented in various formats, including single-select, multiple-select, gap fill, code insertion, sort, and "rearrange" questions. Each question includ...
PCEP Certification Practice Test - Questions, Answers and Explanations Below is a set of 18 questions for the Certified Entry-Level Python Programmer (PCEP) examination focusing on the subtopic "Python Built-In Exceptions Hierarchy: Exception." The questions use various formats, including single and ...
The use of global variables should be minimized in favor of local variables, as global variables can lead to unexpected behavior and make it harder to understand and debug code. It’s generally a good practice to use local variables within functions, and to pass any necessary values as argumen...
Here’s a breakdown of what this code does:Line 1 defines the Point class using the class keyword followed by the class name. Line 2 defines the .__new__() method, which takes the class as its first argument. Note that using cls as the name of this argument is a strong convention ...
Python Questions for Senior and Lead roles Mutable and Immutable Objects Mutable objects (call by reference) Immutable objects (pass by value) Features How objects are passed to FunctionsWays to execute Python code: exec, eval, ast, code, codeop, etc....