Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何找到以双下划线开头的python方法?_Python - Fatal编程技术网

如何找到以双下划线开头的python方法?

如何找到以双下划线开头的python方法?,python,Python,我正在学习python,但当我看到以双下划线开头的函数或变量时,我感到困惑,如: \uuuuu获取属性\uuuuu dict 如何查找以双下划线开头的所有函数和属性,以便?可以更好地理解它们吗?使用内置函数。它返回给定对象中所有属性和方法的列表。这也是一种快速发现功能或调用方法名的好方法。例如: print dir("this is a string") ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__

我正在学习python,但当我看到以双下划线开头的函数或变量时,我感到困惑,如:

\uuuuu获取属性
\uuuuu dict

如何查找以双下划线开头的所有函数和属性,以便?可以更好地理解它们吗?

使用内置函数。它返回给定对象中所有属性和方法的列表。这也是一种快速发现功能或调用方法名的好方法。例如:

print dir("this is a string")

['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__
format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__get
slice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mo
d__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
 '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook
__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center',
 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index
', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper',
'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', '
rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', '
strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
这些方法通常由内置函数或运算符使用。例如,
\uuuuuu eq\uuuuu
测试两个对象是否相等,是否被需要比较值的所有运算符和函数使用

有很多关于这些“神奇方法”的文章和指南,例如

编辑:也是关于这些方法的重要官方文档。它们很好地概括了所有可用的功能。

使用内置功能。它返回给定对象中所有属性和方法的列表。这也是一种快速发现功能或调用方法名的好方法。例如:

print dir("this is a string")

['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__
format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__get
slice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mo
d__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__',
 '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook
__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center',
 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index
', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper',
'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', '
rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', '
strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
这些方法通常由内置函数或运算符使用。例如,
\uuuuuu eq\uuuuu
测试两个对象是否相等,是否被需要比较值的所有运算符和函数使用

有很多关于这些“神奇方法”的文章和指南,例如

编辑:也是关于这些方法的重要官方文档。它们很好地概述了所有可用的内容。

文档是。文档是。另请参见Python语言参考中的。另外,
help(some\u对象)
也很好地概述了
some\u对象
。另请参见Python语言参考中的。另外,
help(some\u对象)
某些对象进行了很好的概述。