Odak modu
return
keyword(anahtar kelime)'u ile sağlayacağız.return
yazmasaydık fonksiyon hiç bir şey döndürmezdi.def fonksiyonun_adı(input):
def square(x):
x*x
fonksiyonun_adı(input)
, bir fonksiyonu çağırmak için inputları ()
'ın içine yazmalıyız. Bazı durumlarda hiç input olmayabilir, bazı durumlarda birden çok olabilir.square(3)
a = square(3)
a
print(a)
None
type(a)
NoneType
type(square(3))
NoneType
return
ile sağlıyoruz.def square(x):
return x * x
square(2)
4
a = square(2)
a
4
b = 4
b + 2
6
1 + square(2)
5
square(9)
ile aynıdır.square(square(3))
81
def weird():
return 5
weird()
5
def square(x):
res = x * x
return res
print("Square of " + str(x) + ": " + str(res))
return
'ün altında yer alıyor.square(4)
16
square(4) + 2
18
def square(x):
res = x * x
print("Square of " + str(x) + ": " + str(res))
return res
square(4)
Square of 4: 16
16
def f(x):
res = x * x
if x % 2 == 0:
return res
else:
return res + 10
print("Square of " + str(x) + ": " + str(res))
f(10)
100
f(13)
179
x = 300
def f(x):
res = x * x
for i in range(10):
res += 20return resprint("hey")
f(10)
120
f(10) + 23
143
def f(x):
res = x * x
for i in range(10):
res += 20
return res
f(10)
300
def f(x):
l = []
res = x * xfor i in range(10):
res += 20l.append(res)
return l
f(10)
[120, 140, 160, 180, 200, 220, 240, 260, 280, 300]
Void Fonksiyonlar (Değer Döndürmeyen Fonksiyonlar)
def f(x):
x = 2
f(2)
f(10) + 4
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-85-abd191062736> in <module>
----> 1 f(10) + 4
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
print(f(3))
None
type(f(3))
NoneType
# Bu kod x in karesini değer olarak bize vermiyor, sadece ekrana bastıracak
def square(x):
print(x,"in/ün/un karesi:", x*x)
square(3)
3 in/ün/un karesi: 9
type(square(4))
4 in/ün/un karesi: 16
NoneType
# hem bir değer bastırıp aynı anda o değeri döndüre de bilirdi
def square(x):
res = x * x
print(x,"in/ün/un karesi:", x*x)
return res
square(4)
4 in/ün/un karesi: 16
16
square(4) + 2
4 in/ün/un karesi: 16
18
Sektörde en çok aranan yazılım becerilerini kazan
Yapay zeka desteği, birebir mentörlük saatleri, canlı dersler ve senin için özel hazırlanmış içeriklerle eksiklerini tamamla, düzenli geri bildirimler al ve öğrenme sürecini en verimli hale getir.
Yunus Emre Kabakcı
Patika+ mezunuPatika+ Fullstack Web Development Bootcamp mezunumuz Yunus Emre,
3 ay içinde Katar’dan aldığı teklif ile, global bir şirket olan Pavo Group’da işe başladı!
“İçerik zenginliği, mentor desteği, ileriye dönük bir network sağlaması ve dünyada en çok tercih edilen frameworkler üzerinden bir eğitim veriyor olması Patika+’ı tercih etmemin temel sebepleri oldu!“
Yorum yapabilmek için derse kayıt olmalısın!