Python Tutorial (1.2)--python Interactive mode

Source: Internet
Author: User

As I said in the previous section, after installing Python, after entering "python" on the command line, if successful, you will get a window similar to the following:

As you can see, there are 3 > symbols (>>>) at the end. >>> is called the python command prompt (prompt), when Python waits for you to enter the code. You can now enter a line of Python code, and Python executes that code. This mode is called Python interactive mode (interactive mode), because Python waits for you to enter the code and execute it.

For example, you can enter an expression for Python to calculate. For example, to calculate the "a", you can enter a "+" at the command prompt, and then press ENTER:

>>> 1 + 1

When you press ENTER, Python outputs the results, which is 2.

To exit Python interaction mode, you can enter exit () at the python command prompt:

>>> exit ()

You can also enter quit ():

>>> quit ()

You can also enter an EOF (end of file) character, on Windows Ctrl+z,linux is ctrl+d.

In the future code, if a line that begins with >>> is present, it means that the line of code is entered in Python interactive mode.

There is a difference between entering code and running a. py file in Python interactive mode. On the python command line, Python will wait for you to enter the code one line at a time, but you don't have the opportunity to run the. py file, and you'll normally run out of a. py file immediately (so you can't see what the program is outputting).

There are more details about the Python interaction pattern, which will be discussed later.

Python Tutorial (1.2)--python Interactive mode

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.