Docstring'ler

Geliştiriciler için Orta Düzey Python

Jasmin Ludolf

Senior Data Science Content Developer

Docstring'ler

  • Bir fonksiyonu tanımlayan metin bloğu

  • Kullanıcıların bir fonksiyonu nasıl kullanacağını açıklar

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.
Geliştiriciler için Orta Düzey Python

Bir docstring'e erişme

# Docstring dahil bilgileri görüntüleyin
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.

None
Geliştiriciler için Orta Düzey Python

Bir docstring'e erişme

# Yalnızca docstring'e erişin
print(round
Geliştiriciler için Orta Düzey Python

Bir docstring'e erişme

# Yalnızca docstring'e erişin
print(round.
Geliştiriciler için Orta Düzey Python

Bir docstring'e erişme

# Yalnızca docstring'e erişin
print(round.__
Geliştiriciler için Orta Düzey Python

Bir docstring'e erişme

# Yalnızca docstring'e erişin
print(round.__doc
Geliştiriciler için Orta Düzey Python

Bir docstring'e erişme

# Yalnızca docstring'e erişin
print(round.__doc__)
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.

$$

$$

  • .__doc__: "dunder-doc" özelliği
Geliştiriciler için Orta Düzey Python

Bir docstring oluşturma

def average(values):

# Tek satırlık docstring """Bir değer dizisinin ortalamasını bulur ve iki ondalığa yuvarlar."""
average_value = sum(values) / len(values) rounded_average = round(average_value, 2) return rounded_average
Geliştiriciler için Orta Düzey Python

Docstring'e erişme

# Docstring'imize erişin
print(average.__doc__)
Bir değer dizisinin ortalamasını bulur ve iki ondalığa yuvarlar.
Geliştiriciler için Orta Düzey Python

Bir docstring'i güncelleme

# Bir fonksiyonun docstring'ini güncelleyin
average.__doc__ = "Calculate the mean of values in a data structure, rounding the results to 2 digits."


print(help(average))
Help on function average in module __main__:

average(values)
    Calculate the mean of values in a data structure, rounding the results to 2 digits.
Geliştiriciler için Orta Düzey Python

Çok satırlı docstring

def average(values):
    """
    Bir değer dizisinin ortalamasını bulur ve iki ondalığa yuvarlar.






    """

average_value = sum(values) / len(values) rounded_average = round(average_value, 2) return rounded_average
Geliştiriciler için Orta Düzey Python

Çok satırlı docstring

def average(values):
    """
    Bir değer dizisinin ortalamasını bulur ve iki ondalığa yuvarlar.

    Args:




    """

average_value = sum(values) / len(values) rounded_average = round(average_value, 2) return rounded_average
Geliştiriciler için Orta Düzey Python

Çok satırlı docstring

def average(values):
    """
    Bir değer dizisinin ortalamasını bulur ve iki ondalığa yuvarlar.

    Args:
        values (list): Sayısal değerlerden oluşan bir liste.



    """

average_value = sum(values) / len(values) rounded_average = round(average_value, 2) return rounded_average
Geliştiriciler için Orta Düzey Python

Çok satırlı docstring

def average(values):
    """
    Bir değer dizisinin ortalamasını bulur ve iki ondalığa yuvarlar.

    Args:
        values (list): Sayısal değerlerden oluşan bir liste.

    Returns:
        rounded_average (float): Değerlerin ortalaması; iki ondalığa yuvarlanmış.
    """

average_value = sum(values) / len(values) rounded_average = round(average_value, 2) return rounded_average
Geliştiriciler için Orta Düzey Python

Docstring'e erişme

# Yardım
print(help(average))
Help on function average in module __main__:

average(values)
    Find the mean in a sequence of values and round to two decimal places.

        Args:
            values (list): A list of numeric values.

        Returns:
            rounded_average (float): The mean of values, rounded to two decimal places.
Geliştiriciler için Orta Düzey Python

Hadi pratik yapalım!

Geliştiriciler için Orta Düzey Python

Preparing Video For Download...