How does Python code run once it’s written? If you ask this question, you must be a beginner in Python. In this article, I’ll show you how to run Python code.

In general, there are two ways to run Python code: from the Interactive Python command line; The other is to use a text editor and run it directly from the command line. Each of these approaches has its advantages and disadvantages. Let’s take a look at the hello World example to open the door to learning Python.

1. Interactive Python command line

(1) What is the command line?

Command line generally refers to the command prompt, that is, in an operating system, a working prompt that prompts for command input. The command prompt varies according to the operating system. For example, in Windows, the command line program is cmd.exe, which is a 32-bit command line program. If “C:\>” appears, it is the command line mode provided by Windows.

(2) What is an interactive command line?

Learning how to use the interactive command line is the first step in learning Python. The Python command line is interactive. You type in a statement to execute, and it immediately gives you the result of executing that statement.

(3) Run the Python code

Enter Python in the CMD window to access the Interactive Python command line. Enter the code directly:

Print 'hello world! 'Copy the code

If you can see the result on the interface, it will be successful!

(4) Analysis of advantages and disadvantages

Interactive interpreters are a great tool for learning The Python language. The advantage is that you get immediate feedback when you type Python statements. The downside of writing a program on Python’s interactive command line is that you can’t save it and have to type it again the next time you want to run it. So, for actual development, we always use a text editor to write Python code and save it as a file so that the program can be run over and over again.

2. Use a text editor

We need to start with “Hello World! The program is written in a text editor, saved, and named, in this case hello. Py, saved in F:\workspace. Note that the file name can only be a combination of letters, digits, and underscores (_).

Enter python F:\workspace\hello.py in the command line. When running, note that the python file storage path is relative. When running, be sure to specify the python file storage path. Otherwise, an error will be reported.

Of course, if you want to run Python code, you can also write it in a text editor while opening an interactive command window and pasting parts of the code to the command line for verification. How does Python code run once it’s written? Everybody clear on that? If you haven’t figured it out yet, follow me now for a more detailed guide to Getting started with Python. Poke the basket word has a surprise ~