Geliştiriciler için Orta Düzey Python
Jasmin Ludolf
Senior Data Science Content Developer
# Özel bir fonksiyon oluşturun
def average(values):
# Ortalamayı hesaplayın
average_value = sum(values) / len(values)
# Sonuçları yuvarlayın
rounded_average = round(average_value, 2)
# Çıktı olarak rounded_average döndürün
return rounded_average
values = Argüman# Pi sayısını 2 basamağa yuvarla
print(round(3.1415926535, 2))
3.14
Değerleri keywords atayarak verin
Yorumlama ve izleme için yararlı
# Pi sayısını 2 basamağa yuvarla
print(round(number=3.1415926535
Değerleri keywords atayarak verin
Yorumlama ve izleme için yararlı
# Pi sayısını 2 basamağa yuvarla
print(round(number=3.1415926535, ndigits=2))
3.14
# help fonksiyonu hakkında daha fazla bilgi alın
print(help(round))
Help on built-in function round in module builtins:
round(number, ndigits=None)
Round a number to a given precision in decimal digits.
The return value is an integer if ndigits is omitted or None. Otherwise,
the return value has the same type as the number. ndigits may be negative.
Help on built-in function round in module builtins:
round(number, ndigits=None)
Round a number to a given precision in decimal digits.
The return value is an integer if ndigits is omitted or None. Otherwise
the return value has the same type as the number. ndigits may be negative.
$$
numberndigitsHelp on built-in function round in module builtins:
round(number, ndigits=None)
Round a number to a given precision in decimal digits.
The return value is an integer if ndigits is omitted or None. Otherwise,
the return value has the same type as the number. ndigits may be negative.
None = değer yok / boş
Varsayılan argüman: bir argüman için default değer belirleme yolu
None değerini 2 ile değiştiriyoruz
Sık kullanılan değer – varsayılan argümanla ayarlayın
# Özel bir fonksiyon oluşturun
def average(values):
average_value = sum(values) / len(values)
rounded_average = round(average_value, 2)
return rounded_average
# Özel bir fonksiyon oluşturun def average(values, rounded=False):
# Özel bir fonksiyon oluşturun def average(values, rounded=False):# rounded True ise ortalamayı iki ondalığa yuvarla if rounded == True:average_value = sum(values) / len(values) rounded_average = round(average_value, 2) return rounded_average
# Özel bir fonksiyon oluşturun def average(values, rounded=False):# rounded True ise ortalamayı iki ondalığa yuvarla if rounded == True: average_value = sum(values) / len(values) rounded_average = round(average_value, 2) return rounded_average# Aksi halde yuvarlama else: average_value = sum(values) / len(values) return average_value
# Hazırlık süreleri listesi (dakika)
preparation_times = [19.23, 15.67, 48.57, 23.45, 12.06, 34.56, 45.67]
# Yuvarlamadan ortalamayı alın
print(average(preparation_times, False))
28.4585714
# Yuvarlamadan ortalamayı alın
print(average(preparation_times))
28.4585714
# Yuvarlanmış ortalamayı alın
print(average(values=preparation_times, rounded=True))
28.46
Geliştiriciler için Orta Düzey Python