Читать книгу Introduction to Python Programming for Business and Social Science Applications - Frederick Kaefer - Страница 21
Executing Python Code in the IDLE Shell Window
ОглавлениеAfter downloading and installing the Python development environment, you can verify that it is properly functioning. The standard distribution of Python comes with an Interactive Development Environment (IDE) named IDLE (for Integrated Development and Learning Environment). An Interactive Development Environment (IDE) contains facilities for writing and editing code as well as testing and debugging code. IDLE runs on Windows, Mac OS X, and UNIX. Documentation for IDLE can be found at https://docs.python.org/3/library/idle.html. The IDLE Python shell window is an interactive interpreter that can execute lines of Python code one at a time. Figure 1.2 is the IDLE Python shell console on Windows, and Figure 1.3 is the IDLE Python shell console on a Mac. Although mostly similar, there are platform-specific variations. For consistency, we will be using Windows-based Python illustrations throughout the remainder of this textbook.
Description
Figure 1.2 The IDLE Python Shell Window on Windows
Description
Figure 1.3 The IDLE Python Shell Window on a Mac
The simplest way to execute Python statements is to type in a Python statement at the shell window command prompt; after the enter key is pressed, the Python interpreter executes the statement. Figure 1.4 illustrates how this works by typing the command print(“Hey, Taxi!”) and pressing enter. Interacting directly with the Python interpreter in this way can be very useful for learning about different Python commands and features. Figure 1.4 also shows four other commands: help, copyright, credits, and license.
Description
Figure 1.4 Executing Python Statement at IDLE Shell Window Command Prompt
Typing help at the command line and pressing enter prompts the user to either enter help() for interactive help or else help(object) for help about a specific object, as shown in Figure 1.5. Figure 1.5 also shows the response for the interactive help, which directs first-time users to a web-based tutorial for the Python version in use, as well as detailed directions on how to use the interactive help utility.
Description
Figure 1.5 Python Help Command at IDLE Shell Window Command Prompt
Lessons learned: In this section, we learned how to write and execute Python code in the IDLE shell window.