Cohorts
  • Discover
  • About Us
  • Blog
  • Patika.dev
  • Web3

Python Temel

Programlama Nedir?
Jupyter Notebook
Temel Veri Tipleri
Değişken Atama
Kafa Karışıklığı
Operatörler ve İfadeler

Stringler
Stringler Üzerinde Operatörler
Stringlerde İndexleme
Stringlerde Casting

Input

Koda Yorum Ekleme

Sayısal Verilerde Karşılaştırma
Stringlerde Karşılaştırma
Mantıksal Operatörler
Short-circuit
Short-circuit Olmayan Mantıksal Operatörler

If-else-elif
Ternary Conditionals

Döngüler
while
for
Continue-Break

List
Tuple
in
Dictionary
Set
Non-scalar Veri Tiplerinde For
Split-Join
List Comprehension
Variable Unpacking
Enumerate-Zip

Fonksiyonlar
return
Comment-Fonksiyon
Birden Fazla Değer Döndürme/input İçerme
Predefined Parameters
Update Input
First Class Function
For-Function

Underscore Placeholder

fstring

Proje


  • Bir fonksiyonu çalıştırdığımızda onun sonucuyla bir şeyler yapmak isteyebilirim. Sonucu bana versin diye özellikle söylemem lazım ve bunu return keyword(anahtar kelime)'u ile sağlayacağız.
  • return yazmasaydık fonksiyon hiç bir şey döndürmezdi.
  • fonksiyon tanımladığımı Python'a anlatmak için yapım:

def fonksiyonun_adı(input):

  • öbür yapılarda da olduğu gibi, bir kod bloğunun belirttiğimiz yapıya ait olduğunu anlatmak için boşluk bırakarak içine yazmamız gerekiyor.
  • Verdiğimiz değerin karesini alan bir fonksiyon yazalım.



def square(x):
    x*x


  • fonksiyonu tanımladıktan sonra tanımladığımız adla onu çağırabiliriz. Yapımız şöyle olacak: 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
  • bize x*x i değer olarak vermedi. Vermesi için bana o değeri döndür diye özellikle söylemem lazım. Bunu return ile sağlıyoruz.
def square(x):

    return x * x
square(2)
4
a = square(2)
a
4


b = 4


b + 2


6
  • Bu döndürülen değerin int 4 'ten bir farkı yok, nereden nasıl geldiği önemli değil, a = 4 dediğimdeki 4 ile aynı. Bu değerle istediğimi yapabilirim
1 + square(2)


5
  • Bilgisayar için o da sadece bir değerdi. Aşağıdaki örnekte de square(3) bize 9 döndürüyor, bilgisayar için aşağıdaki kod, square(9) ile aynıdır.
square(square(3))


81
  • hiç bir inputu olmaya da bilirdi
def weird():
    return 5


weird()


5


  • Fonksiyonlar return'e geldikten sonrasına bakmıyor, return 'ün sağına yazılan değeri veriyor ve fonksiyondan çıkıyor.


def square(x):
    
    res = x * x
    
    return res
    
    print("Square of " + str(x) + ": " + str(res))
    
   
  • Bu yüzden burada bastırma kısmını yapmadı çünkü o kod 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


  • Fonksiyona durumsallık da katabiliriz.


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


  • Fonksiyonların içinde döngü mantığı da olabilir.


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

Quiz

Answer the questions to check your understanding.

This lesson includes a short quiz.

Previous
Next

Lesson discussion

Swap insights and ask questions about “Python Temel”.

Enroll to participate
Start the course to unlock the discussion. Enrolling helps us keep conversations relevant to learners.
Cohorts
WebsiteDiscoverBlogPatika.devRise In
CoursesCircleRustSoliditySolanaWeb3 FundamentalsBlockchain Basics
CompanyAbout UsTerms of UsePrivacy PolicyGDPR NoticeCookies
Don't miss any update!

Disclaimer: The information, programs, and events provided on https://cohorts.patika.dev is strictly for upskilling and networking purposes related to the technical infrastructure of blockchain platforms. We do not provide financial or investment advice, nor do we make any representations regarding the value, profitability, or future price of any blockchain or cryptocurrency. Users are encouraged to conduct their own research and consult with licensed financial professionals before engaging in any investment activities. https://cohorts.patika.dev disclaims any responsibility for financial decisions made by users based on the information provided here.

© 2026 Cohorts, All rights reserved