Skip to content

Commit a0e027e

Browse files
authored
Update README.md
1 parent 76dacb8 commit a0e027e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,33 @@ Decorator funksiya argument sifatida funksiya qabul qiladi.
5959

6060
# Dekorator ishlayapti
6161
# Dekorator uchun ishlatiladigan funksiya
62+
Bitta funksiyada bir nechta decorator ishlatishimiz ham mumkin, bunda birinchisidan boshlab decoratorlar ishlab keladi.
63+
64+
def divide_decorator(func):
65+
def divide_inner(a, b):
66+
try:
67+
return func(a, b)
68+
except ZeroDivisionError:
69+
print("Nolga bo'lish mumkin emas!")
70+
71+
return divide_inner
72+
73+
74+
def second_zero(func): # zero 0 - > 1 function
75+
def inner(a, b):
76+
if b == 0:
77+
b += 1
78+
return func(a, b)
79+
80+
return inner
81+
82+
83+
@second_zero
84+
@divide_decorator
85+
def divider(a, b):
86+
return a / b
87+
88+
89+
print(divider(10, 5)) # 2.0
90+
print(divider(10, 0)) # 10.0
91+

0 commit comments

Comments
 (0)