File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -59,3 +59,33 @@ Decorator funksiya argument sifatida funksiya qabul qiladi.
59
59
60
60
# Dekorator ishlayapti
61
61
# 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
+
You can’t perform that action at this time.
0 commit comments