Exercise 1.3: Cutting and Pasting
This course is structured as a series of traditional web pages where you are encouraged to try interactive Python code samples by typing them out by hand. If you are learning Python for the first time, this "slow approach" is encouraged. You will get a better feel for the language by slowing down, typing things in, and thinking about what you are doing.
If you must "cut and paste" code samples, select code starting after the >>>
prompt and going up to, but not any further than the first blank line or the next >>>
prompt (whichever appears first). Select "copy" from the browser, go to the Python window, and select "paste" to copy it into the Python shell. To get the code to run, you may have to hit "Return" once after you've pasted it in.
Use cut-and-paste to execute the Python statements in this session:
>>> 12 + 20
32
>>> (3 + 4
+ 5 + 6)
18
>>> for i in range(5):
print(i)
0
1
2
3
4
>>>
Warning: It is never possible to paste more than one Python command (statements that appear after >>>
) to the basic Python shell at a time. You have to paste each command one at a time.
Now that you've done this, just remember that you will get more out of the class by typing in code slowly and thinking about it--not cut and pasting.