Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use the dir () function and help () function in python

Shulou Source: shulou.com Published: 2022-05-31 11:13:26 10月01日 Update

This article mainly introduces "how to use the dir () function and help () function in python". In daily operation, I believe that many people have doubts about how to use the dir () function and help () function in python. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about how to use the dir () function and help () function in python. Next, please follow the editor to study!

1. Dir () function

In python, the dir () function can return a list of variables, methods, and defined types in the current range without arguments, while the dir () function can return a list of properties and methods of parameters when it takes parameters.

Syntax:

Dir ([object]) # object refers to objects, variables, types.

Example:

> dir () # get the attribute list of the current module

['_ builtins__','_ _ doc__','_ _ name__','_ _ package__', 'arr',' myslice']

> dir ([]) # how to view 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']

2. Help () function

In python, the help () function is mainly used to view a detailed description of the purpose of a function or module.

Syntax:

Help ([object]) # object refers to an object

Example:

> help ('sys') # View help for the sys module

…… Show help information...

> help ('str') # View help on str data types

…… Show help information...

> a = [1, 2, 2, 3]

> help (a) # View list list help information

…… Show help information...

>

…… Show help information...

At this point, the study on "how to use the dir () function and help () function in python" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Functions help information methods learning parameters modules types variables objects properties more examples syntax utility next data articles theories uses Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Apple Shulou Technology Xiaomi Redmi