面试指南.md 960 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
## 面试指南

### 基础知识

1. 下面的代码会输出什么。

   ```Python
   
   list1 = [1, 2, 3, 4]
   
   list2 = [i for i in list1 if i > 2]
   print(list2)
   
   list3 = [i for i in list1 if i % 2]
   print(list3)
   
   dict1 = {x: x ** 2 for x in (2, 4, 6)}
   print(dict1)
   
   dict2 = {x: f'item{x ** 2}' for x in (2, 4, 6)}
   print(dict2)
   
   set1 = {x for x in 'hello world' if x not in 'abcdefg'}
   print(len(set1))
   ```

2. 下面的代码会输出什么。

    ```Python
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
    
    num = 100
    
    
    def foo():
        num = 200
    
    
    def bar():
        print(num)
    
    
    bar()
    foo()
    bar()
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
    ```

3. 如何修改下面的Python代码,才能够输出“foo in father”?

   ```Python
   
   class Father(object):
   	
   	def foo(self):
   		print('foo in father.')
   
   
   class Son(object):
   	
   	def foo(self):
   		print('foo in son.')
   
   
   obj = Son()
   obj.foo()
   ```