logo资料库

linkedin-pyhon-test.docx

第1页 / 共7页
第2页 / 共7页
第3页 / 共7页
第4页 / 共7页
第5页 / 共7页
第6页 / 共7页
第7页 / 共7页
资料共7页,全文预览结束
1.What is an abstract class? Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation. Abstract classes cannot be instantiated, and require subclasses to provide implementations for the abstract methods. It can only be inherited. 抽象类是一个特殊的类,它的特殊之处在于只能被继承,不能被实例化。如果说类是从一堆对象 中抽取相同的内容而来的,那么抽象类就是从一堆类中抽取相同的内容而来的,内容包括数据属 性和函数属性。 An abstract class exists only so that other concrete class can inherit from the abstract class. 2. What happens when you use built-in function “any()” on a list? any() 函数用于判断给定的可迭代参数 iterable 是否全部为 False,如果是则返回 False,如果有一 个为 True,则返回 True。 3. What data structure does a binary tree degenerate to if it isn’t balanced properly? A degenerate tree is a tree where for each parent node, there is only one associated child node. It is unbalanced and, in the worst case, performance degrades to that of a linked list. 4. What is a static method? A static method does not receive an implicit first argument.  A static method is also a method which is bound to the class and not the object of the class.  A static method can’t access or modify class state.  It is present in a class because it makes sense for the method to be present in class. 静态方法,通过类直接调用,不需要创建对象,不会隐式传递 self,和类本身没有交互,即在静 态方法中,不会涉及到类中的方法和属性的操作。 5. What are attributes? Class attributes belong to the class itself they will be shared by all the instances. Such attributes are defined in the class body parts usually at the top, for legibility.
Unlike class attributes, instance attributes are not shared by objects. Every object has its own copy of the instance attribute (In case of class attributes all object refer to single copy). 6. What is the term used to describe this code? Count, fruit, price = (2, ‘apple’, 3.5) Tuple unpacking 7. What built-in method would you use to remove items from a list? listname.pop(index) / del listname[index] / nums.remove(36) / url.clear() 8. What is one of the most common uses of Python’s sys library? 9. What is a runtime of accessing a value in a dictionary by using its key? O(1) - constant time If you use: 1. if key in dict: It’s O(n) if you use: 1. if dict.get(key): It’s O(1) 10. What is the correct syntax of defining a class called Game? 1. Class Game: 2. pass
11. What is a correct way to write a doctest? """ >>>sum(4, 3) 7 1. def sum(a, b): 2. 3. 4. 5. 6. 7. 8. 9. >>>sum(-4, 5) 1 """ return a + b 12. What built-in python data type is commonly used to represent a stack? List 13. What would this expression return?
14. How does “defaultdict” work? defaultdict create key instead of throwing KeyError 15. What is the correct syntax for defining a class name “Game”, if it inherit from a parent class called “LogicGame”? 16. When would you use a “try/except” block? 17. Which of there is NOT a characteristic of “namedtuples”? Python supports a type of container like dictionaries called “namedtuples()” present in module, “collections“. Like dictionaries they contain keys that are hashed to a particular value. But on contrary, it supports both access from key value and iteration, the functionality that dictionaries lack. Operations on namedtuple(): Access Operations 1. Access by index: The attribute values of namedtuple() are ordered and can be accessed using the index number unlike dictionaries which are not accessible by index. 2. Access by keyname: Access by keyname is also allowed as in dictionaries.
3. using getattr() :- This is yet another way to access the value by giving namedtuple and key value as its argument. No import is needed to use namedtuples because they are available in the standard library 18. What is an instance method? A class is a user-defined blueprint or prototype from which objects are created. Classes provide a means of bundling data and functionality together. Creating a new class creates a new type of object, allowing new instances of that type to be made. Each class instance can have attributes attached to it for maintaining its state. Class instances can also have methods (defined by its class) for modifying its state. Instance method can modify the state of an instance or the state of its parents class. 19. What would happen if you did not alter the state of the element that an algorithm is operating on recursive? You would eventually get a “KeyError” when the recursive portion of the code run out of items to recurse on. 20. Which statement does NOT describe the object-orented programming concept of encapsulation? 21. What is the runtime complexity of searching for an item in a binary search tree? O(logn) = O(h), h is the height of tree 22. What is the algorithmic paradigm of merge sort?
23. Why would you use a decorator? Decorators allow you to define reusable building blocks that can change or extend the behavior of other functions. And they let you do that without permanently modifying the wrapped function itself. The function's behavior changes only when it's decorated. 24. Why would you use a mixin? Mixins are a sort of class that is used to "mix in" extra properties and methods into a class. This allows you to create classes in a compositional style. A mixin is a special kind of multiple inheritance. There are two main situations where mixins are used: 1. You want to provide a lot of optional features for a class. 2. You want to use one particular feature in a lot of different classes. 25. What is the runtime complexity of adding an item to a stack and removing an item from a stack? Python stack can be implemented using deque class from collections module. Deque is preferred over list in the cases where we need quicker append and pop operations from both the ends of the container, as deque provides an O(1) time complexity for append and pop operations as compared to list which provides O(n) time complexity. Add is O(1), remove is O(n) 26.What is the purpose of self keyword when defining or calling instance method? self represents the instance of the class. By using the “self” keyword we can access the attributes and methods of the class in python. It binds the attributes with the given arguments. The reason you need to use self. is because Python does not use the @ syntax to refer to instance attributes. “self” refers to the instance whose method was called. 27. which choice is the most syntactically correct example of conditional branching?
28. What is the purpose of an if/else statement? The if/else statement executes a block of code if a specified condition is true. If the condition is false, another block of code can be executed. 29. Which of the following is true about how numeric data would be organized in a binary search tree? Binary Search Tree is a node-based binary tree data structure which has the following properties:  The left subtree of a node contains only nodes with keys lesser than the node’s key.  The right subtree of a node contains only nodes with keys greater than the node’s key.  The left and right subtree each must also be a binary search tree. 30. Running time of the code? 1. def my_print(a_list, b_list): 2. 3. 4. for b in b_list: print(a, b) for a in a_list:
分享到:
收藏