Python trung cấp dành cho nhà phát triển
Jasmin Ludolf
Senior Data Science Content Developer
Chuỗi (khối văn bản) mô tả một hàm
Giúp người dùng hiểu cách dùng hàm
Help on built-in function round in module builtins: round(number, ndigits=None)Làm tròn một số đến độ chính xác (số chữ số thập phân) cho trước. Giá trị trả về là số nguyên nếu bỏ qua ndigits hoặc bằng None. Ngược lại giá trị trả về có cùng kiểu với số. ndigits có thể âm.
# Truy cập thông tin, gồm cả docstring
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
# Chỉ truy cập docstring
print(round
# Chỉ truy cập docstring
print(round.
# Chỉ truy cập docstring
print(round.__
# Chỉ truy cập docstring
print(round.__doc
# Chỉ truy cập docstring
print(round.__doc__)
Làm tròn một số đến độ chính xác (số chữ số thập phân) cho trước.
Giá trị trả về là số nguyên nếu bỏ qua ndigits hoặc bằng None. Ngược lại,
giá trị trả về có cùng kiểu với số. ndigits có thể âm.
$$
$$
.__doc__: thuộc tính "dunder-doc"def average(values):# Docstring một dòng """Tìm giá trị trung bình của một dãy và làm tròn đến hai chữ số thập phân."""average_value = sum(values) / len(values) rounded_average = round(average_value, 2) return rounded_average
# Truy cập docstring của chúng ta
print(average.__doc__)
Tìm giá trị trung bình của một dãy và làm tròn đến hai chữ số thập phân.
# Cập nhật docstring của hàm 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.
def average(values): """ Tìm giá trị trung bình của một dãy và làm tròn đến hai chữ số thập phân. """average_value = sum(values) / len(values) rounded_average = round(average_value, 2) return rounded_average
def average(values): """ Tìm giá trị trung bình của một dãy và làm tròn đến hai chữ số thập phân. Args: """average_value = sum(values) / len(values) rounded_average = round(average_value, 2) return rounded_average
def average(values): """ Tìm giá trị trung bình của một dãy và làm tròn đến hai chữ số thập phân. Args: values (list): Danh sách các giá trị số. """average_value = sum(values) / len(values) rounded_average = round(average_value, 2) return rounded_average
def average(values): """ Tìm giá trị trung bình của một dãy và làm tròn đến hai chữ số thập phân. Args: values (list): Danh sách các giá trị số. Returns: rounded_average (float): Trung bình, làm tròn đến hai chữ số thập phân. """average_value = sum(values) / len(values) rounded_average = round(average_value, 2) return rounded_average
# Trợ giúp
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.
Python trung cấp dành cho nhà phát triển