Learn Python documentation from the old man,

Source: Internet
Author: User

Learn Python documentation from the old man,

Documentation is important. The sword tips, the heart of yijinjing, And the hacker who wrote the evil sword spectrum are all documents. Even those cool people need these documents. What's more, what about us? Therefore, documents are very important.

Documentation. To put it bluntly, we use word (this is the most popular) and so on (pay attention to this and wait for all the tools that are not commonly used, including the vim tool used when I edited the text) A document written by a text writing tool that contains but is not limited to text. It's a bit cool. The purpose is to be rigorous. It is better to come up with a more convincing definition, of course, from Wikipedia.

Copy codeThe Code is as follows:
A software or source code document is a text entity associated with the software system and its software engineering process. Document types include software requirement documents, design documents, Test Documents, user manuals, etc. The Requirement documents, design documents, and test documents are generally written by developers during software development, non-process documents such as user manuals are written by specialized non-technical writers.
 
Early software documents mainly refer to user manuals. According to Barker's definition, documents are used to record the design, planning, and implementation processes of software system interface elements, to enhance the availability of the system. Forward believes that software documents are used as a means of communication between software engineers. The communication information is mainly related to the developed software system. Parnas emphasizes the authority of the document, and he believes that the document should provide a precise description of the software system.
 
To sum up, we can define the software documentation:

1. The document is a written description of the software system;
2. The document shall accurately describe the software system;
3. Software Documents are a form of communication between software engineers;
4. There are many types of documents, including software requirement documents, design documents, Test Documents, user manuals, etc;
5. There are many ways to present documents. They can be traditional forms of written text or charts, or dynamic web pages.

So what does the Python document refer to here? One aspect is that every learner needs to learn python. What are the things that python developers (all of them are cool) provide to us? Can we give them the opportunity to understand the meaning and usage of each function and command in python?

Yes. They have prepared more than one Daniel.

View python documentation

Sincerely, I would like to tell everyone who has read this tutorial that it is necessary to read the documentation for the sublimation of programming. The document is better than all the tutorials, all the teachers, and all the experts. Why? The reason is that you must wait for the viewer to understand it and then understand it after understanding it.

Python document URL: Example.

In addition to reading documents on the website, is there any other way?

Yes, and it is no stranger to the audience. It has been used many times in this tutorial, that is, dir () and help ()
Copy codeThe Code is as follows:
>>> Dir (list)
['_ Add _', '_ class _', '_ ins INS _', '_ delattr __', '_ delitem _', '_ delslice _', '_ doc _', '_ eq _', '_ format __', '_ ge _', '_ getattribute _', '_ getitem _', '_ getslice _', '_ gt __', '_ hash _', '_ iadd _', '_ imul _', '_ init _', '_ iter __', '_ le _', '_ len _', '_ lt _', '_ mul _', '_ ne __', '_ new _', '_ reduce _', '_ performance_ex _', '_ repr _', '_ reversed __', '_ rmul _', '_ setattr _', '_ setitem _', '_ setslice _', '_ sizeof __', '_ str _', '_ subclasshook _', 'append', 'Count', 'extend', 'index', 'insert', 'pop ', 'delete', 'reverse', 'sort ']

>>> Help (list. _ mul __)

Help on wrapper_descriptor:

_ Mul __(...)
X. _ mul _ (n) <=> x * n

This document viewing method is frequently used in interactive mode, which is fast and convenient. Please remember and use it.

As mentioned earlier, there is also a document: doc, help is actually called in this function.
Copy codeThe Code is as follows:
>>> Print (list. _ mul _. _ doc _) # consistent with the content displayed by help (list. _ mul _)
X. _ mul _ (n) <=> x * n

>>> Print (list. index. _ doc _) # view the index document
L. index (value, [start, [stop])-> integer -- return first index of value.
Raises ValueError if the value is not present.

Add documents to your programs

When you write your own program, you also hope to have a function similar to the python document above. You can view your program document in some way, so that you can look at your own.

One way is to use three double quotes or single quotes in your program, and write the relevant content in the middle.
Copy codeThe Code is as follows:
>>> Def qiwsir ():
... "I like python """
... Print "http://qiwsir.github.io"
...
>>> Qiwsir ()
Http://qiwsir.github.io

>>> Print (qiwsir. _ doc _) # use this method to view the documentation in the function you write.
I like python

>>> Help (qiwsir) # The content displayed by calling _ doc _

Help on function qiwsir in module _ main __:

Qiwsir ()
I like python

In addition, for a file, you can put the instructions before the file without affecting the file code running.

For example, a python file with the extension. py has the following content:
Copy codeThe Code is as follows:
#! /Usr/bin/env python
# Coding: UTF-8

Import random

Number = random. randint (1,100)

Guess = 0

While True:

Num_input = raw_input ("please input one integer that is in 1 to 100 :")
Guess + = 1

If not num_input.isdigit ():
Print "Please input interger ."
Elif int (num_input) <0 and int (num_input) >=100:
Print "The number shoshould be in 1 to 100 ."
Else:
If number = int (num_input ):
Print "OK, you are good. It is only % d, then you successed." % guess
Break
Elif number> int (num_input ):
Print "your number is more less ."
Elif number <int (num_input ):
Print "your number is bigger ."
Else:
Print "There is something bad, I will not work"

This program is a guess number game used in "use while to loop". It is stored in a file named 205-2.py. If you want to write a document for this program, you can do this.
Copy codeThe Code is as follows:
"""
This is a game.
I am Qiwei.
I like python.
I am writing python articles in my website.
My website is http://qiwsir.github.io
You can learn python free in it.
"""

#! /Usr/bin/env python
# Coding: UTF-8

Import random

Number = random. randint (1,100)

Guess = 0

While True:

Num_input = raw_input ("please input one integer that is in 1 to 100 :")
Guess + = 1

If not num_input.isdigit ():
Print "Please input interger ."
Elif int (num_input) <0 and int (num_input) >=100:
Print "The number shoshould be in 1 to 100 ."
Else:
If number = int (num_input ):
Print "OK, you are good. It is only % d, then you successed." % guess
Break
Elif number> int (num_input ):
Print "your number is more less ."
Elif number <int (num_input ):
Print "your number is bigger ."
Else:
Print "There is something bad, I will not work"

Finally, we recommend a fairly good article to share with the column:

Python introspection guide: How to monitor your Python objects




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.