How can I install Python correctly?

Source: Internet
Author: User

For the first time I came into contact with Python users and scholars, it is very important to understand the concept of the Python language. let's first talk about what is the Python language, the so-called Python language: it is a widely used computer programming language.

This chapter is a quick start to Python. This Chapter does not cover special rules and details of python. It aims to help you quickly understand the characteristics of Python through examples. This chapter briefly introduces the basic concepts of variables, expressions, control flows, functions, and input/output. This Chapter does not cover the advanced features of the Python language. Even so, experienced programmers can still create advanced programs by reading the materials in this chapter. We encourage new users to experience Python by running examples.

This statement calculates the value of the expression and then assigns the calculation result to the principal variable as its new value. When a value assignment occurs, principal's initial bound value of 1000 is discarded. The value assignment ends. Not only does the principal binding value change, but its type also changes with the assignment action. In this example, because rate is a floating point number, after the value assignment is complete, principal also becomes a floating point number.

In Python, each statement ends with a line break. Of course, you can write multiple statements in one line. In this case, the statements must be separated by semicolons, as shown below:

 
 
  1. 1 class Stack (object ):
  2. 2 def _ init _ (self): # initialize the stack
  3. 3Self. stack= []
  4. 4 def push (self, object ):
  5. 5 self. stack. append (object)
  6. 6 def pop (self ):
  7. 7 return self. stack. pop ()
  8. 8 def length (self ):
  9. 9 return len (self. stack)

We recommend that you use this method only for debugging statements, because you can easily Delete All debugging statements by deleting only one line.) The while statement first checks the loop conditions behind it. If the condition expression is true, it executes the statement block after the colon and tests the loop condition again until it is false.

The statement block after the colon is a loop body. Note: The Python language uses indentation blocks to indicate program logic. Other languages use braces ). In Listing 1.1, the three statements after the while statement are the cyclic bodies and are executed in each loop.

Python installation does not specify the number of blank spaces (spaces and tabs) for indentation. The only requirement is that statements at the same level must have the same indentation blank. Note: either it is a space, and if it is a tab, do not mix it.) the disadvantage of the program beauty in Listing 1.1 is that the output is not very nice.

To make it more beautiful, you can use a format string to keep the calculation result only two digits after the decimal point: expression [float (s) for s in svalues] Create a new list by cyclically listing all strings in svalues and running the function float () for each element.

This special list creation method is called list comprehension ). After all the strings in the list are converted to floating point numbers, the built-in functions min () and max () calculate the maximum and minimum values in the list. In class definition, methods are defined using def statements. The first parameter of each method in the class always references the class instance object itself. We are used to using the self name to represent this parameter.

However, this is just a habit. You can use any other name if you like. But to make it easy for others to understand your program, it is best to follow your habits. To call the attributes of an instance object, you must explicitly use the self variable (as shown above ).

  • How to call Python correctly
  • Complete parsing of Python code
  • Analysis of powerful Python applications
  • Analysis on the Python application of Hu HU shengwei
  • Analysis of Python Functions

As your program grows larger, you may need to split it into multiple related files for ease of modification and maintenance. Python allows you to put the function definition or public part into a file, and then import the file as a module in other programs or scripts. Create a module and put the corresponding statements and definitions into a file. The file name is the module name.

Install Python extension and embedding. Many standard modules provided by Python support C or C ++ interfaces. Python and C can work together and can be embedded into C or C ++ applications. Therefore, the Python language can provide scripting interfaces for applications, because it supports cross-language development.

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.