Lambda ifadeleri # 2 - Python Dersleri (Tutorials)

in #palnet7 years ago

kapak.jpg

Merhabalar

Python programlama derslerinin bu dersinde lambda ifadeleri ile devam edeceğiz. Bir önceki dersimizde "lambda" ifadelerini niye kullandığımızdan bahsetmiş genel yapısı üzerinde durmuştuk.

Bu dersimizde "lambda" ifadeleri ile alakalı olarak değinmediğimiz noktaları göreceğiz.

"lambda" ifadelerini kullanarak, listelerdeki "List Comprehension" gibi tek satırda fonksiyon tanımlayabiliriz. Örnek bir uygulama yapalım:

Örneğimizde klasik bir yöntemle topla() adında 3 parametre alan bir fonksiyon tanımladık. Sonrasında fonksiyonu print() fonksiyonu içerisinde çağırıp değerini ekrana yazdırdık.

Bu fonksiyonu "lambda" ifadesi ile oluşturmak isteseydik sonuç aşağıdaki gibi olurdu :

Örnekte de görüldüğü gibi kullanımı oldukça basit. Atama operatörünün sol tarafında fonksiyon ismi yer alırken hemen sağ tarafında "lambda" ifadesi yer alıyor.

"lambda" ifadesinin hemen sağında parametreler, iki nokta üst üste işaretinden hemen sonra da kod kısmı bulunuyor.

Genel kullanımı bu yönde. Anlaşılması için bir örnek daha yapalım :

Örneğimizde stTersCevir() adında tek parametre alan bir fonksiyon bulunuyor.

st[ : : -1]

kodu ile stringin tersini alıp return anahtar kelimesi ile sonucu döndürüyor. Bunu "lambda" ifadesini kullanarak tekrardan düzenleyelim:

Görüldüğü gibi "lambda" ifadesini kullanmak programcıya oldukça pratiklik sağlar..

Ancak fark ettiniz mi bilmiyorum lambda ifadeleri, çok işlem satırlı fonksiyonlarda kullanılamaz. Tek işlem satırı olan basit fonksiyonlar için uygulanabilir.

Şimdilik bu kadar.

Umarım faydalı bir çalışma olmuştur.

Teşekkürler.

yesilayrca.png

Kaynak belirtilmeyen görseller bana aittir. The pictures without source in the post is belong to me

Sort:  

Congratulations @elektroyazilim! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You received more than 6000 upvotes. Your next target is to reach 7000 upvotes.

You can view your badges on your Steem Board and compare to others on the Steem Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

You can upvote this notification to help all Steem users. Learn how here!

The force is with you! You got a 57.14% upvote from @steemyoda courtesy of @elektroyazilim!

You got a 21.00% upvote from @minnowvotes courtesy of @elektroyazilim!

You got a 33.33% upvote from @whalecreator courtesy of @elektroyazilim! Delegate your Steem Power to earn 100% payouts.

Thank you so much for using our service! Congratulations! You've earned an ROI of 107.70% with bids of: 0.062$

Received 22.16% upvote from @onlyprofitbot courtesy of @elektroyazilim!

Want to earn more with us? Our APR can reach as high as
13% or more!

More portion of profit will be given to delegators, as the SP pool grows!

Comment below or any post with "@opb !delegate [DelegationAmount]" to find out about current APR, estimated daily earnings in SBD/STEEM

You can now also make bids by commenting "@opb !vote post [BidAmount] [SBD|STEEM]" on any post without the hassle of pasting url to memo!

* Please note you do not have to key in [] for the command to work, APR can be affected by STEEM prices

Sneaky-Ninja-Throwing-Coin 125px.jpg
Defended (33.33%)
Summoned by @elektroyazilim
Sneaky Ninja supports @youarehope and @tarc with a percentage of all bids.
Everything You Need To Know About Sneaky Ninja


woosh

You got a 21.74% upvote from @redlambo courtesy of @elektroyazilim! Make sure to use tag #redlambo to be considered for the curation post!

Coin Marketplace

STEEM 0.04
TRX 0.33
JST 0.079
BTC 63100.12
ETH 1669.66
USDT 1.00
SBD 0.41