正在加载图片...
1.6.THE MAGIC OF PYTHON 5 Source Code Compiler Machine (Program) Code Running Inputs Program Outputs Figure 1.2:Compiling a High-Level Language Source Code Computer (Program) Running an Outputs Interpreter Inputs Figure 1.3:Interpreting a High-Level Language. Each kind of computer has its own machine language.A program for a Pentium CPU won't run on a Mac- intosh that sports a PowerPC.On the other hand,a program written in a high-level language can be run on many different kinds of computers as long as there is a suitable compiler or interpreter(which is just another program).For example,if I design a new computer,I can also program a Python interpreter for it,and then any program written in Python can be run on my new computer,as is. 1.6 The Magic of Python Now that you have all the technical details,it's time to start having fun with Python.The ultimate goal is to make the computer do our bidding.To this end,we will write programs that control the computational processes inside the machine.You have already seen that there is no magic in this process,but in some ways programming feels like magic. The computational processes inside the computer are like magical spirits that we can harness for our work.Unfortunately,those spirits only understand a very arcane language that we do not know.What we need is a friendly Genie that can direct the spirits to fulfill our wishes.Our Genie is a Python interpreter.We can give instructions to the Python interpreter,and it directs the underlying spirits to carry out our demands. We communicate with the Genie through a special language of spells and incantations(i.e.,Python).The best way to start learning about Python is to let our Genie out of the bottle and try some spells. You can start the Python interpreter in an interactive mode and type in some commands to see what happens.When you first start the interpreter program,you may see something like the following: Python2.1(#1,Jun212001,11:39:00) [GCC pgcc-2.91.66 19990314 (egcs-1.1.2 release)]on linux2 Type "copyright","credits"or "license"for more information. >>> The>>is a Python prompt indicating that the Genie is waiting for us to give it a command.In programming languages,a complete command is called a statement. Here is a sample interaction with the Python interpreter.1.6. THE MAGIC OF PYTHON 5 (Program) Compiler Machine Code Running Inputs Outputs Source Code Program Figure 1.2: Compiling a High-Level Language Code Computer Inputs Outputs Source (Program) Running an Interpreter Figure 1.3: Interpreting a High-Level Language. Each kind of computer has its own machine language. A program for a Pentium CPU won’t run on a Mac￾intosh that sports a PowerPC. On the other hand, a program written in a high-level language can be run on many different kinds of computers as long as there is a suitable compiler or interpreter (which is just another program). For example, if I design a new computer, I can also program a Python interpreter for it, and then any program written in Python can be run on my new computer, as is. 1.6 The Magic of Python Now that you have all the technical details, it’s time to start having fun with Python. The ultimate goal is to make the computer do our bidding. To this end, we will write programs that control the computational processes inside the machine. You have already seen that there is no magic in this process, but in some ways programming feels like magic. The computational processes inside the computer are like magical spirits that we can harness for our work. Unfortunately, those spirits only understand a very arcane language that we do not know. What we need is a friendly Genie that can direct the spirits to fulfill our wishes. Our Genie is a Python interpreter. We can give instructions to the Python interpreter, and it directs the underlying spirits to carry out our demands. We communicate with the Genie through a special language of spells and incantations (i.e., Python). The best way to start learning about Python is to let our Genie out of the bottle and try some spells. You can start the Python interpreter in an interactive mode and type in some commands to see what happens. When you first start the interpreter program, you may see something like the following: Python 2.1 (#1, Jun 21 2001, 11:39:00) [GCC pgcc-2.91.66 19990314 (egcs-1.1.2 release)] on linux2 Type "copyright", "credits" or "license" for more information. >>> The ￾✁￾✁￾ is a Python prompt indicating that the Genie is waiting for us to give it a command. In programming languages, a complete command is called a statement. Here is a sample interaction with the Python interpreter
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有