Using the built-in document Python3 efficient learning resources and official Chinese documents

From the front of the basics of Python method introduction, we are almost to explore Python's built around practice methods, such as built-in methods strings, lists, dictionaries and other data structures, and a large number of built-in standard library, such as functools, time, threadingetc., how quickly we learn to master and learn to use this tool set Python it? We can use a lot of resources Python's built-in document either grasp on many basic use Python toolset.

dir function

Python built-in dirmethod functions for extracting all of the properties of an object,, and the attributes of the object, such as a method of

L = [1, 2, 3, 4]
print(dir(L))
print([])

Sample results:

['__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']
['__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']

You can see that we can pass an instance of an object to view its properties, you can type directly into its built-empty object to view the corresponding property, we can even directly into the name of the type to get a list of corresponding properties:

print(dir(list))

Sample results:

['__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']

Although we get a property of an object, but we still do not know the meaning of these property methods, then we can use the document to help us continue to learn string object properties.

Docstring: DOC

Document is automatically generated by the string Python, generated within the content and placement depends on our position, the document is a comment character string, on the module files, as well as functions of the top class statement, then the package will automatically character Python string, that is, a so-called documentation strings through an object __doc__to see carried out.

def two_sum(x, y):
    '''
    Used to calculate the sum of two numbers
    '''
    return x + y

print(two_sum.__doc__)

Sample results:

Used to calculate the sum of two numbers

The above example of a process to achieve the function (for calculating the sum of two numbers) binding documents and view documents string string. We can also see some of the built-in type of a property specific use, such as viewing a list of objects in popthe specific meaning and usage

L = [1, 2, 3, 4]
print(L.pop.__doc__)

Sample results:

L.pop([index]) -> item -- remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range.

PyDoc: help function

We can use documents and other information strings in Python show objects help function tool more user-friendly structured, for help for some larger object content will be divided into several sections, even detailed information interactive display object.

help(list)

Interaction results:

Help on class list in module __builtin__:

class list(object)
 |  list() -> new empty list
 |  list(iterable) -> new list initialized from iterable's items
 |
 |  Methods defined here:
 |
 |  __add__(...)
 |      x.__add__(y) <==> x+y
 |
 |  __contains__(...)
 |      x.__contains__(y) <==> y in x
 |
 |  __delitem__(...)
 |      x.__delitem__(y) <==> del x[y]
 |
 |  __delslice__(...)
 |      x.__delslice__(i, j) <==> del x[i:j]
 |
-- More  --

For example, we can see all the details and usage attributes of the list and so on through the help, see more information Enter.

Official Chinese documents

English reading will be difficult for a small partner, a new Python official Chinese document is a good learning experience tutorials: docs.python.org/zh-cn/3/ , from introductory tutorials, standard library in Python to advanced features everything , considered a good learning resources and a common ** "Python dictionary" **.

We will certainly encounter many difficulties when learning python, as well as the pursuit of new technologies, here's what we recommend learning Python buckle qun: 784758214, here is the python learner gathering place! ! At the same time, he was a senior development engineer python, python script from basic to web development, reptiles, django, data mining and other projects to combat zero-based data are finishing. Given to every little python partner! Daily share some methods of learning and the need to pay attention to small details

Click: Python technology sharing

Guess you like

Origin blog.csdn.net/zhizhun88/article/details/91465304