Python Basic Learning Chapter II

Source: Internet
Author: User
Tags python script

One. How Python runs the program

1. Writing code in interactive mode

The simplest way to run a Python program is to enter the program on the Python interactive command line. Of course there are many ways to start such a command line, such as the IDE, the system terminal. If you already have an interpreter installed on your computer and you can run it, you can enter a python program. You can also use the system's own Black Window command mode, which is the most basic way to enter commands, windows in the press Win+r input cmd to enter the command prompt environment. Here's a look at the operation (output Hello World):

Perhaps the Python version is relatively high, and typing print ' Hello World ' enter at the command line is an error. But the output like the following is true:

These prerequisites are for you to install Python into your personal computer first.

2. Writing code in interactive prompt mode has the following tips

(1) Only Python commands can be entered

(2) If you want to output the result in a file, you must use the PRINT statement

(3) No indentation is required in interactive prompt mode. When entering a Python program, either in interactive mode or in a text file, make sure that all statements that are not nested are in the first column, which is leftmost. If this is not the case, Python will print syntaxerror information.

(4) Be aware of the prompt transformation and conformance statements. The prompt changes when you enter a compound statement with multiple lines after two lines in interactive mode. In the Shell window interface, the interaction prompt is changed from >>> to the second and subsequent lines. 。 In the idle interface, the rows after the first line are automatically indented.

3. System command line and file

At the interactive command line, Python will disappear once the input program is executed. The code entered in interactive mode is not saved to a file and must be entered from the beginning to run again. To save the program, write the code to the file. There are many ways to run the code in a file, in the system command line, by clicking on the icon, by selecting it in the idle user interface, and so on. Files that contain code that can be run are often called modules, and module files that can be run directly are called scripts. It should be noted here that the Python script has a. py file name extension. Another interesting thing is that you can redirect (redirect the input stream) Python output to a file (in the system's shell interface). The general usage is as follows:

Python test.py > Saveit.txt so the output in test.py will be saved to the Saveit.txt file!

Tried it:

Python Basic Learning Chapter II

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.