current position:Home>The introduction method of executing Python source code or Python source code file (novice, please enter the old bird and turn left)

The introduction method of executing Python source code or Python source code file (novice, please enter the old bird and turn left)

2022-01-31 01:20:21 Programmer Zhang Yixiao

「 This is my participation 11 The fourth of the yuegengwen challenge 3 God , Check out the activity details :2021 One last more challenge

At the beginning Python when , We always want to execute the code right away , But clearly follow the tutorial step by step , How to report errors on the full screen ?

 Report errors .jpeg
The screenshot above appears because there is no clear distinction between when to enter python Interactive mode , When you don't need to enter python Interactive mode .

Let's distinguish what is Python Source code and Python The source code file :

  1. Python Source code :Python Source code , for example
print("hello world")
 Copy code 
  1. Python The source code file : One content is Python Source code files , Is similar to the doc A document is a document whose content is text . A file named hello.py The document of Python The source code file .

yuanmawenj.png

When you need to enter Python Interactive mode ?
When it comes to python The source code needs to enter Python Interactive mode :

  1. Input... At the terminal python
  2. Enter your... In this terminal window Python Source code

 Interactive mode .png

The biggest convenience of interactive mode is that you can get the execution result of code faster . One line of input gets one line of output , Very suitable for debugging simple code .

When you don't need to enter Python Interaction mode ?
When it comes to Python Source file , You don't need to enter Python Interactive mode , Call directly Python The interpreter can .
At this time, the calling format is : python python Source file path

  1. Access terminal
  2. python python Source file path

 file .png
summary :
When it comes to python The source code needs to enter Python Interactive mode ;
When it comes to Python Source file , You don't need to enter Python Interactive mode , Call directly Python The interpreter can .

copyright notice
author[Programmer Zhang Yixiao],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/01/202201310120188324.html

Random recommended