Use of Dir () and help () in Python

Source: Internet
Author: User
Tags iterable tag name xpath

Python contains a number of built-in functions, class method properties, and various modules. We can use the Dir () function and the Help () function to get the information we want in Python idle interactive mode when we want to understand what property methods are available for a type and how each method is used. Dir ()

Dir () is used to query a class or all properties of an object, such as:

>>>dir (list) ['__add__','__class__','__contains__','__delattr__','__delitem__','__dir__','__doc__','__eq__','__format__','__ge__','__getattribute__','__getitem__','__gt__','__hash__','__iadd__','__imul__','__init__','__iter__','__le__','__len__','__lt__','__mul__','__ne__','__new__','__reduce__','__reduce_ex__','__repr__','__reversed__','__rmul__','__setattr__','__setitem__','__sizeof__','__str__','__subclasshook__','Append','Clear','Copy','Count','Extend','Index','Insert','Pop','Remove','Reverse','Sort']>>>
Help ()

The Help () function helps us understand the details of modules, types, objects, methods, properties

1. Help view type details, including how the class is created, properties, methods

>>>Help (list)classListinchModule Builtins:classList (object)| List ()New Empty list| List (iterable), new list initialized fromIterable's Items| |Methods defined here:| |__add__(Self, value,/) | Return self+value.| |__contains__(Self, key,/) | Return KeyinchSelf .| |__delitem__(Self, key,/) |Delete Self[key].| |__eq__(Self, value,/) | Return self==value.| |__ge__(Self, value,/) | Return self>=value.| |__getattribute__(Self, name,/) |Return getattr (self, name).| |__getitem__(...) | X.__getitem__(y) <==>X[y]| |__gt__(Self, value,/) | Return self>value.| |__iadd__(Self, value,/) | Implement self+=value.| |__imul__(Self, value,/) | Implement self*=value.| |__init__(Self,/, *args, * *Kwargs)--More--

2. Help to view detailed usage information of the method (be careful to enter the full path when using, need to import the module first when using the module Help)

>>> fromSelenium.webdriver.common.byImport by>>> Help onclassByinchModule selenium.webdriver.common.by:classby (Builtins.object)|Set of supported locator strategies.| |Data descriptors defined here:| |__dict__| Dictionary forInstance variables (ifdefined)| |__weakref__| List of weak references to the object (ifdefined)| |  ---------------------------------------------------------------------- | Data andOther attributes defined here:| | Class_name ='class name'| | Css_selector ='CSS Selector'| | ID ='ID'| | Link_text ='Link Text'| | NAME ='name'| | Partial_link_text ='Partial link text'| | Tag_name ='Tag Name'| | XPATH ='XPath'>>>

Use of Dir () and help () in Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.