Before Start

Before writing the first Python program, let's review what is the command line mode and the Python interactive mode.

Command line mode

Select "Command Prompt" from the Windows Start menu to enter the command line mode. Its prompt is similar to C: >:

Interactive mode

Type the command python in the command line mode, you will see a bunch of text output similar to the following, and then enter the Python interactive mode, its prompt is >>>.

Enter exit () in the Python interactive mode and press Enter to exit the Python interactive mode and return to the command line mode:

You can also select the Python (command line) menu item directly from the Start menu to enter the Python interactive mode directly, but the window will close directly after entering exit (), and will not return to the command line mode.

Start Coding

Knowing how to start and exit Python's interactive mode, we can start writing Python code.

At the prompt >>> in interactive mode, enter the code directly and press Enter to get the code execution result immediately. Now, try typing 100 + 200 and see if the result is 300:

>>> 100 + 200

Quite simply, any valid mathematical calculation can be calculated.
If you want Python to print the specified text, you can use the print () function, and then surround the text you want to print with quotes, but you cannot mix ' and ":

>>> print('hello, world')
hello, world

This type of text enclosed in single or double quotes is called a string in the program, and we will often encounter it in the future.
Finally, use exit() to exit, our first Python program is complete!

Last modified: January 9, 2020



Leave a Reply