Kaggle官方课程链接:Functions and Getting Help
本专栏旨在Kaggle官方课程的汉化,让大家更方便地看懂。
目录
Functions Applied to Functions
Functions and Getting Help
调用函数并定义我们自己的函数,并使用Python的内置文档
您已经看到并使用了打印和abs等功能。但是Python有更多的函数,定义自己的函数是Python编程的重要组成部分。
在本课中,您将了解有关使用和定义函数的更多信息。
Getting Help
您在前面的教程中看到了abs函数,但如果您忘记了它的功能怎么办?
help()函数可能是你能学到的最重要的Python函数。如果你能记住如何使用help(),那么你就掌握了理解大多数其他函数的关键。
以下是一个示例:
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()显示两件事:
1.该函数轮的头部(number,ndigits=None)。在这种情况下,这个告诉我们round()采用了一个我们可以描述为数字的参数。此外,我们可以选择给出一个单独的参数,可以将其描述为ndigits。
2.函数功能的简要英文描述。
常见陷阱:当你查找一个函数时,记得传入函数本身的名称,而不是调用该函数的结果。
如果我们在调用函数round()时调用help会发生什么?
help(round(-2.01))
Help on int object:
class int(object)
| int([x]) -> integer
| int(x, base=10) -> integer
|
| Convert a number or string to an integer, or return 0 if no arguments
| are given. If x is a number, return x.__int__(). For floating point
| numbers, this truncates towards zero.
|
| If x is not a number or if base is given, then x must be a string,
| bytes, or bytearray instance representing an integer literal in the
| given base. The literal can be preceded by '+' or '-' and be surrounded
| by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
| Base 0 means to interpret the base from the string as an integer literal.
| >>> int('0b100', base=0)
| 4
|
| Methods defined here:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __and__(self, value, /)
| Return self&value.
|
| __bool__(self, /)
| self != 0
|
| __ceil__(...)
| Ceiling of an Integral returns itself.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(...)
| Flooring an Integral returns itself.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __format__(self, format_spec, /)
| Default object formatter.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __index__(self, /)
| Return self converted to an integer, if self is suitable for use as an index into a list.
|
| __int__(self, /)
| int(self)
|
| __invert__(self, /)
| ~self
|
| __le__(self, value, /)
| Return self<=value.
|
| __lshift__(self, value, /)
| Return self<<value.
|

1262

被折叠的 条评论
为什么被折叠?



