一个段代码定义如下,下列调用结果正确的是?
def bar(multiple):
def foo(n):
return multiple ** n
return foo
正确答案: A 你的答案: A (正确)
bar(2)(3) == 8
bar(2)(3) == 6
bar(3)(2) == 8
bar(3)(2) == 6
解析
# -*- coding: utf-8 -*-
def bar(multiple):
def foo(n):
return multiple ** n
return foo
print(bar(2)(3) == 8)
# result
True
What gets printed?()
print r"\nwoow"
正确答案: C 你的答案: C (正确)
new line then the string: woow
the text exactly like this: r"\nwoow"
the text like exactly like this: \nwoow
the letter r and then newline then the text: woow
the letter r then the text like this: nwoow
解析
>print(r"\nwoow")
\nwoow
有如下类定义,下列描述错误的是?
class A(object):
pass
class B(A):
pass
b = B()
正确答案: D 你的答案: D (正确)
isinstance(b, A) == True
isinstance(b, object) == True
issubclass(B, A) == True
issubclass(b, B) == True
解析
- isinstance() 函数来判断一个对象是否是一个已知的类型,类似 type()。
- isinstance() 与 type() 区别:
- type() 不会认为子类是一种父类类型,不考虑继承关系。
- isinstance() 会认为子类是一种父类类型,考虑继承关系。
- 参数
- object – 实例对象。
- classinfo – 可以是直接或间接类名、基本类型或者由它们组成的