Python Learning to organize--3/3

Source: Internet
Author: User

Today again learn the language of Python, with a new purpose and up one-year-old himself, in fact, as early as last summer has learned a period of time, but finally died, this time I really hope to master a practical language to enrich themselves, before the study of either C or Java, Self-feeling in addition to do not use a point, but I feel python this language once learned can be used to do a lot of things, for this, I also opened this microblogging, in order to record and supervise their way of learning!


1, Python is an object-oriented interpretation of computer programming language, the interpretation of different from the compiled language, interpretation of real-time interpretation, compile one-off compilation.

At the same time, object-oriented is different from the process-oriented, the process is to analyze the steps needed to solve the problem, and then use the function of the steps to achieve the step-by-step implementation, using the time one by one to call it.

Object-oriented is the decomposition of a problem transaction into individual objects, the purpose of which is not to complete a single step, but to describe the behavior of something in the whole process of solving the problem.

For example, the process-oriented design is the first step in the analysis of the problem: 1, start the game, 2, Sunspot first go, 3, draw the screen, 4, Judge Win and lose, 5, turn to white son, 6, draw the screen, 7, Judge Win and lose, 8, return step 2,9, output the final result. The problem is solved by using separate functions for each of the above steps.

The object-oriented design is to solve the problem from another idea. The whole Gobang can be divided into 1, black and white both sides, the behavior of the two parties is exactly the same, 2, the Board system, responsible for drawing the screen, 3, the rule system, responsible for determining such as foul, winning and losing. The first Class object (Player object) is responsible for accepting user input, and informs the second class object (Checkerboard object) The change of the chess piece layout, the Checkerboard object receives the change of the chess piece to be responsible to show this change on the screen, and uses the third kind of object (rule system) to decide the chess game.

It is obvious that object-oriented is a function to divide a problem, not a step. The same is the game, the behavior in the process-oriented design scattered in the total number of steps, there is likely to be different drawing version, because the designers often consider the actual situation of a variety of simplification. In object-oriented design, the drawing can only appear in the Checkerboard object, thus guaranteeing the unification of the drawing.


2, Python variables are pointing to the relationship, different from the C language memory relationship, so it is not possible to modify the variable name to point to the contents of the data unit.


Python's data type does not need to specify the type, which is different from the C language, and thus becomes more concise.


3.print () formatted output

Print (Format (value, format word)

Eg:print (Format (12.345, ' 6.3f '))

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/7C/D0/wKiom1bYMxjgnVKxAABvGN9RZAc559.png "title=" af.png "alt=" Wkiom1bymxjgnvkxaabvgn9rzac559.png "/>

When the number of positions is greater than the number of digits in the original value, the output value is aligned to the right, leaving the corresponding spaces in front.

When the placeholder is less than the number of digits in the original value, the format is ignored and the number of digits of the original value is still printed.


4, Python's library is very large and rich

eg

Import Math;

import OS; listdir display directory files, GETCWD display the current working directory

Import socket; gethostbyname returns the domain address of the website (gethostbyname (' www.baidu.com ')


That ' s all

Python Learning to organize--3/3

Related Article

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.