What does dir mean in python?

藏色散人
Release: 2019-06-24 13:49:10
Original
11037 people have browsed it

What does dir mean in python?

What does dir mean in python?

When the dir() function in python takes no parameters, it returns the current List of variables, methods and defined types within the scope; when parameters are taken, a list of properties and methods of the parameters is returned. If the argument contains the method __dir__(), this method will be called. If the parameter does not contain __dir__(), this method will collect parameter information to the maximum extent possible.

dir Syntax:

dir([object])
Copy after login

Parameter description:

object -- object, variable, type.

Return value

Returns the attribute list of the module.

The following example shows how to use dir:

>>>dir()   #  获得当前模块的属性列表
['__builtins__', '__doc__', '__name__', '__package__', 'arr', 'myslice']
>>> dir([ ])    # 查看列表的方法
['__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']
>>>
Copy after login

Related recommendations: "Python Tutorial"

The above is the detailed content of What does dir mean in python?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template