你好 我们喜欢有关编程语言的测验。 我们已经在博客上发布了三个:第一个 -使用Python,PHP,Golang,DevOps, 第二个 -完全在Go中, 第三个 -仅在PHP中。 今天的测验专门针对Python。
我们邀请您热烈庆祝另一个夏季周的结束以及在PyCon Russia 2018前夕。 (顺便说一下,谁去?我们会在那里)。
削减-七个问题,来自朋友Chapaev的建议,来自ABBA的摘录( 什么?是的! )和一个不错的礼物。
UPD:我们已完成接受答案。 感谢所有参加的人! 问题的答案在正文中,获奖者和获奖者位于破坏者的下面。

奖品
奖项将在前十名中分配。 第一个正确回答Python测验问题的人,我们将发送一个高级的Avito-merch套件:运动衫,袜子和空心骨头-您可以猜测新项目将使用哪种后端语言和前端框架编写。 第二位完成任务的参与者将获得短绒棉,袜子和T恤。 第三个将获得相同的套装,但没有T恤/运动衫。 在剩下的七名参与者中,我们将玩一个带有卡宾枪的保温瓶,甚至在远足时也可以带上卡宾枪,至少是在黑客马拉松比赛中。

问题
*在所有情况下,我们都在谈论Python 3。
问题1
变量t
的结果是什么:
>>> t = (1, 2, [30,40]) >>> t[2] += [50, 60]
答案选项:
TypeError
将飞出,在(1, 2, [30, 40, 50, 60])
,TypeError
将飞出,在(1, 2, [30, 40])
,(1, 2, [30, 40, 50, 60])
,(1, 2, [30, 40])
。
正确答案TypeError
将飞出,在t
为(1, 2, [30, 40, 50, 60])
问题2
您是否具有这样的模块结构:
foo_app/ snatch/ qwerty.py bar_app/ snatch/ mamamia.py
如何做到这一点,以便您可以通过以下方式在代码中导入这些模块:
from snatch import qwerty, mamamia
答案选项:
问题3
有一个脚本:
class A: def get_some(self): super().get_some() class B: def get_some(self): print('Some') class C(A, B): def get_some(self): super().get_some() c = C() c.get_some()
输出是什么?
答案选项:
AttributeError: 'C' object has no attribute 'get_some'
,AttributeError: 'super' object has no attribute 'get_some'
,Some
- 空虚(没有查帕耶夫)。
问题4
运行此代码时将显示什么:
class A: def foo(self): print('foo A') class B: def foo(self): print('foo B') class C(A, B): def foo(self): super().foo() class D(B, A): def foo(self): super().foo() class E(C, D): pass e = E() e.foo()
答案选项
foo A
,foo B
,TypeError: Cannot create a consistent method resolution order (MRO) for bases A, B
正确答案TypeError: Cannot create a consistent method resolution order (MRO) for bases A, B
问题5
假设您有一个模块foo.py:
def bar(): print(', !')
然后运行另一个脚本:
import importlib import foo from foo import bar input(', ') importlib.reload(foo) bar()
等待输入时,您更改foo.py模块:
def bar(): print(', !')
接下来,您在foo.py中按“输入”,使其继续工作,您会看到...
答案选项:
ModuleReloadedException: method bar() was reloaded
,, !
,, !
,- 空虚(再也没有查帕耶夫)。
问题6
运行此代码时将显示什么:
class A: def __init__(self): print('__init__ A', end=' ') class B: def __init__(self): print('__init__ B', end=' ') class C(A, B): pass c = C()
答案选项:
__init__ A __init__ B
__init__ B __init__ A
__init__ A
__init__ B
问题7
执行以下代码后,输出将是什么?
def not_(value): return not value result = not_(0), all(any([not_(x) for x in range(b)]) for b in range(10)) print(result)
答案选项:
总结
我们将在7月25日(星期三)更新该帖子,以发布问题的答案。 如果您决定-将答案放在破坏者的下面,以便其他参与者对解决问题更感兴趣。
还有(!)测验结束后,请不要忘记检查Habr的帐户。