- Learn Programming in Python with Cody Jackson
- Cody Jackson
- 550字
- 2021-06-10 19:06:06
Using the Python command prompt
Your Terminal should look similar to the screenshot labeled Python 3 prompt. Notice that the command to launch the interpreter is actually python3. If both Python 2 and Python 3 are installed on the system, you need to expressly indicate which version to use; otherwise, the system default will be used, which may be different from what is desired. The screenshot labeled Default Python prompt shows what the default prompt on the author's system looks like.
Anaconda is a customized Python distribution (https://www.anaconda.com) that includes a large number of data science and machine learning tools by default, making it easier for users to manage their environment. This simply demonstrates that, in addition to multiple Python versions, different Python distributions can be installed on the same system, each one customized to a particular use. Below is an example of the interactive Python shell for a vanilla Python installation:
In addition, the astute reader will see there is a difference in the Python environment between the different versions. The following screenshot states that the Python 3 environment is standard Python, whereas the preceding screenshot shows that Python 2 is part of the Anaconda distribution:

For the most part, you won't even notice which version is in use; for example, version 3.4 versus 3.7, unless you are using a library, function, or method for a specific version. Then, you can simply add a special code to identify what version the user has and provide notification to upgrade, or you can modify your code so it is backwards-compatible.
The >>> characters in the preceding screenshot is the Python command prompt; your code is typed here and the result is printed on the following line, without a prompt. For example, the following screenshot shows how the user can interact with the Python interpreter just like using a normal operating system command prompt.
If you write a statement that doesn't require any processing by Python, it will simply return you to the prompt, awaiting your next order. In the previous example, the print() function simply takes the text that is placed in the parentheses and prints it to the screen. Python doesn't have to do anything with this, in terms of performing calculations or anything, so it prints the statement and then waits for a new command.
(By the way, Python was named after Monty Python, not the snake. Hence, some of the code you'll find on the internet, and tutorial, and books will have references to Monty Python sketches.)
The standard Python interpreter can be used to test ideas before you put them in your code. This is a good way to test the logic required to make a particular function work correctly or see how a conditional loop will work. You can also use the interpreter as a simple calculator; if you import various mathematical libraries, you can perform complex calculations as well.
The following screenshot shows the Python interpreter being used for simple arithmetic; it also shows that the math library is imported so more complex calculations can be performed (importing libraries will be covered in more detail in the Importing modules section):
- C#高級編程(第10版) C# 6 & .NET Core 1.0 (.NET開發經典名著)
- Android Jetpack開發:原理解析與應用實戰
- 深入淺出Java虛擬機:JVM原理與實戰
- Hands-On Natural Language Processing with Python
- R語言與網絡輿情處理
- Windows內核編程
- OpenCV 4計算機視覺項目實戰(原書第2版)
- Julia for Data Science
- Cocos2d-x Game Development Blueprints
- 深入實踐Kotlin元編程
- JavaScript從入門到精通(視頻實戰版)
- Android應用開發實戰(第2版)
- 大學計算機應用基礎(Windows 7+Office 2010)(IC3)
- 深度學習入門:基于Python的理論與實現
- Android應用開發攻略