Telegram Group & Telegram Channel
Python dasturlash maktabi
Funksiyalar (vazifalar) Oldindan belgilangan funksiyalarni ishlatishdan tashqari, def operatoridan foydalanib o'zingizning funksiyalaringizni yaratishingiz mumkin. Funksiya xuddi o'zgaruvchilarga o'xshab oldin yoziladi va keyin chaqiriladi. Funksiyadagi kod…
Ⓜ️ lambda funksiyasi

Python lambdalari kichik, nomsiz funktsiyalar bo'lib, oddiy Python funksiyalariga qaraganda imkoniyatlari kam, ammo ixchamroq sintaksisga ega.Lambda funksiyalari istalgan miqdordagi argumentlarga ega bo'lishi mumkin, ammo funksiya faqat bitta ifodani qaytaradi.


def pythonuz(x):
return x

pythonuz nomli oddiy funksiya x argumentini o'ziga oldi va uni qaytardi.Shu funksiyani lambda ko'rinishi

lambda x: x

3 ta argumentdan iborat lambda funksiyasiga namuna:
x = lambda a, b, c: a * b + c
print(x(4, 5, 6))
26

Argumentga 1 sonini qo'shuvchi lambda funksiyani 2 xil ko'rinishda ishga tushirib ko'ramiz.
1) O'zgaruvchiga lambda berish orqa
li
pythonuz = lambda x: x + 1
print(pythonuz(3))
4

2) Funksiya va uning argumentini alohida qavsga olish orqali
print((lambda x: x + 1)(3))
4

Nomsiz funksiyalar o'rni oddiy funksiyalar ichida ishlatilganda seziladi.


def oddiy(n):
return lambda a: a * n


nomsiz = oddiy(2)
print(nomsiz(11))

22


def myfunc(n):
return lambda a : a * n


mydoubler = myfunc(2)
mytripler = myfunc(3)
print(mydoubler(11))
print(mytripler(11))

22
33


Lambda ichida shartlarni ham tekshirishimiz mumkin.Sonlarni juft yoki toq ekanini aniqlovchi lambda funksiyasini yozamiz.
print((lambda x: (x % 2 and 'toq son' or 'juft son'))(4))
juft son


Quyida 1, 2 va 3 sonlar yig'indisini hisoblovchi lambda funksiyalarni har xil uslubda yozib ishga tushiramiz.
(lambda x, y, z: x + y + z)(1, 2, 3)
6
(lambda x, y, z=3: x + y + z)(1, 2)
6
(lambda x, y, z=3: x + y + z)(1, y=2)
6
(lambda *args: sum(args))(1,2,3)
6
(lambda **kwargs: sum(kwargs.values()))(one=1, two=2, three=3)
6
(lambda x, *, y=0, z=0: x + y + z)(1, y=2, z=3)
6

@pythonuz



tg-me.com/pythonuz/556
Create:
Last Update:

Ⓜ️ lambda funksiyasi

Python lambdalari kichik, nomsiz funktsiyalar bo'lib, oddiy Python funksiyalariga qaraganda imkoniyatlari kam, ammo ixchamroq sintaksisga ega.Lambda funksiyalari istalgan miqdordagi argumentlarga ega bo'lishi mumkin, ammo funksiya faqat bitta ifodani qaytaradi.


def pythonuz(x):
return x

pythonuz nomli oddiy funksiya x argumentini o'ziga oldi va uni qaytardi.Shu funksiyani lambda ko'rinishi

lambda x: x

3 ta argumentdan iborat lambda funksiyasiga namuna:
x = lambda a, b, c: a * b + c
print(x(4, 5, 6))
26

Argumentga 1 sonini qo'shuvchi lambda funksiyani 2 xil ko'rinishda ishga tushirib ko'ramiz.
1) O'zgaruvchiga lambda berish orqa
li
pythonuz = lambda x: x + 1
print(pythonuz(3))
4

2) Funksiya va uning argumentini alohida qavsga olish orqali
print((lambda x: x + 1)(3))
4

Nomsiz funksiyalar o'rni oddiy funksiyalar ichida ishlatilganda seziladi.


def oddiy(n):
return lambda a: a * n


nomsiz = oddiy(2)
print(nomsiz(11))

22


def myfunc(n):
return lambda a : a * n


mydoubler = myfunc(2)
mytripler = myfunc(3)
print(mydoubler(11))
print(mytripler(11))

22
33


Lambda ichida shartlarni ham tekshirishimiz mumkin.Sonlarni juft yoki toq ekanini aniqlovchi lambda funksiyasini yozamiz.
print((lambda x: (x % 2 and 'toq son' or 'juft son'))(4))
juft son


Quyida 1, 2 va 3 sonlar yig'indisini hisoblovchi lambda funksiyalarni har xil uslubda yozib ishga tushiramiz.
(lambda x, y, z: x + y + z)(1, 2, 3)
6
(lambda x, y, z=3: x + y + z)(1, 2)
6
(lambda x, y, z=3: x + y + z)(1, y=2)
6
(lambda *args: sum(args))(1,2,3)
6
(lambda **kwargs: sum(kwargs.values()))(one=1, two=2, three=3)
6
(lambda x, *, y=0, z=0: x + y + z)(1, y=2, z=3)
6

@pythonuz

BY Python dasturlash maktabi




Share with your friend now:
tg-me.com/pythonuz/556

View MORE
Open in Telegram


Python dasturlash maktabi Telegram | DID YOU KNOW?

Date: |

That strategy is the acquisition of a value-priced company by a growth company. Using the growth company's higher-priced stock for the acquisition can produce outsized revenue and earnings growth. Even better is the use of cash, particularly in a growth period when financial aggressiveness is accepted and even positively viewed.he key public rationale behind this strategy is synergy - the 1+1=3 view. In many cases, synergy does occur and is valuable. However, in other cases, particularly as the strategy gains popularity, it doesn't. Joining two different organizations, workforces and cultures is a challenge. Simply putting two separate organizations together necessarily creates disruptions and conflicts that can undermine both operations.

Telegram auto-delete message, expiring invites, and more

elegram is updating its messaging app with options for auto-deleting messages, expiring invite links, and new unlimited groups, the company shared in a blog post. Much like Signal, Telegram received a burst of new users in the confusion over WhatsApp’s privacy policy and now the company is adopting features that were already part of its competitors’ apps, features which offer more security and privacy. Auto-deleting messages were already possible in Telegram’s encrypted Secret Chats, but this new update for iOS and Android adds the option to make messages disappear in any kind of chat. Auto-delete can be enabled inside of chats, and set to delete either 24 hours or seven days after messages are sent. Auto-delete won’t remove every message though; if a message was sent before the feature was turned on, it’ll stick around. Telegram’s competitors have had similar features: WhatsApp introduced a feature in 2020 and Signal has had disappearing messages since at least 2016.

Python dasturlash maktabi from sg


Telegram Python dasturlash maktabi
FROM USA