11# 1.1 Python
22
3- In this part, we'll start with the absolute basics of Python.
4-
53### What is Python?
64
75Python is an interpreted high level programming language. It is often classified as a
86[ "scripting language"] ( https://en.wikipedia.org/wiki/Scripting_language ) and
9- is considered to be similar to languages such as Perl, Tcl, or Ruby. The syntax
7+ is considered similar to languages such as Perl, Tcl, or Ruby. The syntax
108of Python is loosely inspired by elements of C programming.
119
1210Python was created by Guido van Rossum around 1990 who named it in honor of Monty Python.
1311
1412### Where to get Python?
1513
1614[ Python.org] ( https://www.python.org/ ) is where you obtain Python. For the purposes of this course, you
17- only need a basic installation. We recommend installing Python 3.6 or newer. We will be using Python3 in
18- our solutions and notes .
15+ only need a basic installation. I recommend installing Python 3.6 or newer. Python 3.6 is used in the notes
16+ and solutions .
1917
2018### Why was Python created?
2119
22- According to Guido :
20+ In the words of Python's creator :
2321
2422> My original motivation for creating Python was the perceived need
2523> for a higher level language in the Amoeba [ Operating Systems]
@@ -34,9 +32,9 @@ According to Guido:
3432### Where is Python on my Machine?
3533
3634Although there are many environments in which you might run Python,
37- this course has you run Python programs from the terminal or command
38- shell. From the terminal, you should be able to type a command such as
39- this:
35+ Python is typically installed on your machine as a program that runs
36+ from the terminal or command shell. From the terminal, you should be
37+ able to type ` python ` like this:
4038
4139```
4240bash $ python
@@ -51,15 +49,15 @@ hello world
5149If you are new to using the shell or a terminal, you should probably
5250stop, finish a short tutorial on that first, and then return here.
5351
54- Just so you know, you will become a much better Python programmer if
55- you are able to run, debug, and interact with Python at the terminal
56- shell. This is Python's native environment . If you are able to use
57- Python in the shell, you will be able to use virtually everywhere
58- else.
52+ Although there are many non-shell environments where you can code
53+ Python, you will be a stronger Python programmer if you are able to
54+ run, debug, and interact with Python at the terminal . This is
55+ Python's native environment. If you are able to use Python here, you
56+ will be able to use it everywhere else.
5957
6058## Exercises
6159
62- ### (a) Using Python as a Calculator
60+ ### Exercise 1.1: Using Python as a Calculator
6361
6462On your machine, start Python and use it as a calulator to solve the
6563following problem.
@@ -85,7 +83,7 @@ broker takes their 20% cut?
8583>>>
8684```
8785
88- ### (b) Getting help
86+ ### Exercise 1.2: Getting help
8987
9088Use the ` help() ` command to get help on the ` abs() ` function. Then use
9189` help() ` to get help on the ` round() ` function. Type ` help() ` just by
@@ -101,18 +99,19 @@ Followup: Go to <http://docs.python.org> and find the documentation for
10199the ` abs() ` function (hint: it’s found under the library reference
102100related to built-in functions).
103101
104- ### (c) Cutting and Pasting
102+ ### Exercise 1.3: Cutting and Pasting
105103
106- As you've noticed, this course is structured as a series of traditional
107- web pages where you are encouraged to try interactive code samples by typing them
108- by hand. If you are learning Python for the first time, this is encouraged.
109- You will get a better feel for the language by slowing down, typing things in,
110- and thinking about what you are doing.
104+ This course is structured as a series of traditional web pages where
105+ you are encouraged to try interactive Python code samples ** by typing
106+ them out by hand.** If you are learning Python for the first time,
107+ this "slow approach" is encouraged. You will get a better feel for
108+ the language by slowing down, typing things in, and thinking about
109+ what you are doing.
111110
112- If you are inclined to use "cut and paste" in the editor , select code
111+ If you must "cut and paste" code samples , select code
113112starting after the ` >>> ` prompt and going up to, but not any further
114113than the first blank line or the next ` >>> ` prompt (whichever appears
115- first). Select "copy" from the brower , go to the Python window, and
114+ first). Select "copy" from the browser , go to the Python window, and
116115select "paste" to copy it into the Python shell. To get the code to
117116run, you may have to hit "Return" once after you’ve pasted it in.
118117
@@ -139,12 +138,14 @@ Warning: It is never possible to paste more than one Python command
139138(statements that appear after ` >>> ` ) to the basic Python shell at a
140139time. You have to paste each command one at a time.
141140
142- ### (d) Where is My Bus?
141+ Now that you've done this, just remember that you will get more out of
142+ the class by typing in code slowly and thinking about it--not cut and pasting.
143+
144+ ### Exercise 1.4: Where is My Bus?
143145
144- If you’ve made it this far, try something more advanced and type these
145- statements to find out how long people waiting on the corner of Clark
146- street and Balmoral in Chicago will have to wait for the next
147- northbound CTA \# 22 bus:
146+ Try something more advanced and type these statements to find out how
147+ long people waiting on the corner of Clark street and Balmoral in
148+ Chicago will have to wait for the next northbound CTA \# 22 bus:
148149
149150``` pycon
150151>>> import urllib.request
@@ -181,5 +182,8 @@ exercise work. For example:
181182>>>
182183```
183184
185+ If you can't make this work, don't worry about it. The rest of this course
186+ has nothing to do with parsing XML.
187+
184188[ Contents] ( ../Contents ) \| [ Next (1.2 A First Program)] ( 02_Hello_world )
185189
0 commit comments