面试题集锦


一、

print(1 > 2 or 3 and 4 < 6)  
  print(2 or 3 and 4 < 6) 2
  执行结果为:True  2
  分析:先计算比较运算符的结果,然后在计算逻辑运算符的结果
View Code

二、

class Foo:
    def __init__(self):
        self.func()
    def func(self):
        print('in Foo')

class Son(Foo):
    def func(self):
        print('in Son')

s1 = Son()
#in Son
View Code

    

三、

class Foo:
    Country = 'China'
    def func(self):
        print(self.Country)

class Son(Foo):
    Country = 'English'
    def func(self):     # 走这个方法
        print(self.Country)

s = Son()
s.func()

#English
View Code


四、

 
class Foo:
    Country = 'China'
    def func(self):  # 走这个方法
        print(self.Country)

class Son(Foo):
    Country = 'English'

s = Son()
s.func()   # English
View Code


五、

class Foo:
    Country = 'China'
    def func(self):
        print(self.Country)

class Son(Foo):pass

s = Son()
s.func()   # 'China'
View Code


原文地址:https://www.cnblogs.com/echo-up/p/9417775.html