Python learning notes-python program running, python-python

Source: Internet
Author: User

Python learning notes-python program running, python-python

I am a beginner in python and write down some of my ideas. Please ignore it.

Install the python editor and configure the environment (see install and configure python editor in http://www.cnblogs.com/lynn-li/p/5885001.html ). Because python versions 2. x are incompatible with 3. x, and 3. x is constantly evolving and unstable. Therefore, we recommend that you install 2.x, which is 2.7.x.

After the installation and configuration are complete, we can write the first python program. Brothers and sisters who have learned other languages know that the entry program of the language is hello world. So here we also use hello world to open the door to python learning.

Running Environment: Windows python configuration complete

Python can be run in two ways: one is to run in python interactive command line; the other is to run directly in command line using a text editor.

Note: The above two running methods are compiled and run using the CPython interpreter. Of course, you can also write python code into eclipse, run with the JPython interpreter, you need to configure the environment yourself, the specific configuration can refer to: http://www.cnblogs.com/lynn-li/p/5885163.html

I. Command Line and interactive command line

First, you must understand the concept of this command line.

1. Command Line

Definition: the command line mode in Windows is similar to "C: \> ".

Mode: in Windows, press win + r to enter

 

2. Interactive command line

Definition: ">>>" is displayed, which is the interactive command line of python.

Mode: Enter python in the Windows command line.

 

Ii. Run python code in interactive command lines

In the cmd window, enter python and enter the python interactive command line. Enter the code directly:

Print 'Hello world! '

 

The running result is displayed, indicating that the operation is successful!

The advantage of writing a program in Python's interactive command line is that you can get the result at a glance. The disadvantage is that you cannot save it. You have to repeat it next time when you want to run it.

Therefore, in actual development, we always use a text editor to write code, write it, and save it as a file, so that the program can run repeatedly.

3. Run python code through the command line

1. Write and save python code

We will set "hello world !" The program is written in a text editor, saved, and named. Here we name it hello. py and saved to F: \ workspace.

Note the following when naming:

1) the file must end with. py. None of the above can be used.

2) the file name can only be a combination of English letters, numbers, and underscores.

Recommended Text Editor: Notepad ++ and Sublime Text

2. Run python code

In command line mode, enter python F: \ workspace \ hello. py to run successfully.

Note:

1) the python file storage path is relative. During running, you must specify the python file storage path,

Otherwise, an error is reported:

Can't open file 'hello. py'

 

Of course, if you use Python to develop programs, you can write code in the text editor and open an interactive command window. During code writing, part of the code is stuck to the command line for verification, get twice the result!

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.