Python'da Fonksiyonlara Giriş
Hugo Bowne-Anderson
Instructor
Tüm nesneler bir betiğin her yerinden erişilebilir değildir
Kapsam: Bir nesneye/adına erişilebilen program bölümü
Global kapsam: Betiğin ana gövdesinde tanımlıdır
Yerel kapsam: Bir fonksiyon içinde tanımlıdır
Yerleşik kapsam: Ön tanımlı built-ins modülündeki adlar
def square(value): """Returns the square of a number.""" new_val = value ** 2 return new_valsquare(3)
9
new_val
<hr />----------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-3-3cc6c6de5c5c> in <module>()
<hr />-> 1 new_value
NameError: name 'new_val' is not defined
new_val = 10 def square(value): """Returns the square of a number.""" new_val = value ** 2 return new_valsquare(3)
9
new_val
10
new_val = 10 def square(value): """Returns the square of a number.""" new_value2 = new_val ** 2 return new_value2square(3)
100
new_val = 20
square(new_val)
400
new_val = 10 def square(value): """Returns the square of a number.""" global new_val new_val = new_val ** 2 return new_valsquare(3)
100
new_val
100
Python'da Fonksiyonlara Giriş