Python dir() Function

Python 内置函数Python Built-in Functions


Description

dir()When the function is called without parameters, it returns a list of variables, methods, and defined types in the current scope; when called with a parameter, it returns a list of the parameter's attributes and methods. If the parameter contains the method __dir__(), that method will be called. If the parameter does not contain __dir__(), the method will collect parameter information to the greatest extent.

Syntax

dir syntax:

dir([object])

Parameter description:

  • object -- object, variable, type.

Return Value

Returns a list of module attributes.

Example

The following example demonstrates how to use dir:

>>>dir() # Get the attribute list of the current module ['__builtins__', '__doc__', '__name__', '__package__', 'arr', 'myslice'] >>> dir([ ]) # View the methods of the list ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] >>>

Python 内置函数Python Built-in Functions

Other Extensions