Python Fundamentals Review

  1. Given the following three list, how would you create a new list that matches the desired output printed below
    fruits = [‘apples’, ‘oranges’, ‘bananas’]
    quantities = [5, 3,4]
    prices = [1.5, 2,2, 0,89]

#Desired output
[(‘Apples’, 5, 1.5), …
Answer: use zip()
2. how does defaultDict work?
3. for functions that does not return anything, None will be return by default.
4. Python support multiple inherits, but not Java
5. use list.pop(item) to remove item from the list
6. the list data structure in Python can represents queue and stack
7. map() is used for (each item in an iterable and returns the value of that function.)
8. any() is used for: it returns True if any items in this list is true, otherwise, it’s false.
9. all() is used for: it returns True if all items in this list is true, otherwise, it’s false.
10.what is the difference between set and list in Python? set is an unordered collections of unique items and list is an ordered collection of non-unique items.
10. what is a class method? class method can modify the state of the class, but they can’t directly modify the state of an instance that inherits from that class. actually I have an article about all those method types, please refer to that.
11. what is "“space complexity”? the amount of space taken up in memory as a function of the input size. => memoryuse(input)
12. 什么是namedtuples?namedtuple is a subclass of the tuple. tuple的item只能通过index访问元素 但是namedtuple可以通过item的name进行访问。please check the following example:

coordinate = namedtuple('Coordinate', ['x', 'y'])
co = coordinate(10,20)
print co.x,co.y
  1. the pass keyword in python: Pass语句就是一个占位符
posted @ 2020-10-18 05:27  EvanMeetTheWorld  阅读(20)  评论(0)    收藏  举报