Questions #1



Download 85,32 Kb.
bet6/24
Sana06.07.2022
Hajmi85,32 Kb.
#752107
1   2   3   4   5   6   7   8   9   ...   24
Bog'liq
interview en

def foo (bar = []):
bar append( 1 )
return bar
foo()
>>> [ 1 ]
foo()
[ 1 , 1 ]
foo()
>>> [ 1 , 1 , 1 ]

It is considered good practice to specify an empty immutable value for the parameter, for example 0, None, '', False. In the body of the function, check for fullness and create a new collection:


def foo (bar = None ):
if bar is None :
bar = []
bar append( 1 )
return bar
foo()
>>> [ 1 ]
foo()
>>> [ 1 ]
foo()
>>> [ 1 ]

The above is relevant incl. for sets and dictionaries.


Is it possible to pass a function as an argument to another function?
It is possible, a function in Python is a first-order object: it allows assignment, transfer to a function, deletion.
Is it possible to declare a function inside another function? Where will she be seen?
Can. Such a function will only be visible inside the first function.
What are lambdas? What are their features?
These are anonymous functions. They do not reserve a name in a namespace. Lambdas are often passed to map, reduce, filter functions.
Lambdas in Python can only consist of one expression. Using the parenthesis syntax, you can wrap the body of a lambda into multiple lines.
You cannot use a semicolon to separate statements.
Are the following expressions allowed?

  • nope=lambda:pass

  • riser = lambda x: raise Exception(x)

No, loading the module will throw a SyntaxError exception. The body of a lambda can only contain an expression. pass and raise are statements.

Decorators


What are decorators? Why are they needed?
Decorator in a broad sense is a design pattern when one object changes the behavior of another. In Python, a decorator is usually a function A that takes a function B and returns a function C. In this case, the C function uses the B function in itself.
To decorate a function means to replace it with the result of the decorator.

Download 85,32 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   ...   24




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish