@@ -16,10 +16,11 @@ Python 3 is preferable, being the newest version out!
1616
1717.. note::
1818
19- On Windows, you'll want to add :program:`Python` to your path, so it
20- can be found by other programs. To do this, navigate to your
21- installation directory (:file:`C:\\Python33\\`), open the :file:`Tools`,
22- then :file:`Scripts` folders, and run the :file:`win_add2path.py`
19+ On Windows, you'll want to add :program:`Python` to your PATH, so it
20+ can be found by other programs. With Python 3.5 or later, there should be
21+ and option to do this in the installer. Otherwise, you can navigate to your
22+ installation directory (:file:`C:\\Python34\\`), open the :file:`Tools`,
23+ then :file:`Scripts` folder, and run the :file:`win_add2path.py`
2324 file by double clicking on it.
2425
2526And a Code Editor
@@ -32,6 +33,10 @@ favourite knife. To start off with, you'll just want a basic, easy-to-use one
3233that doesn't get in your way, but is still effective at writing python code.
3334Here are some suggestions for those:
3435
36+ - `Atom`_: A new code editor available for Windows, Mac and Linux. It's
37+ an open-source project developed by GitHub and is very easy to add
38+ functionality for, with its packages system.
39+
3540- `Sublime Text`_: A great all around editor that's easy to use. It's Ctl+B
3641 shortcut lets you run the python file you're working on straight away. Runs
3742 on Windows, Mac and Linux.
@@ -48,6 +53,7 @@ Here are some suggestions for those:
4853- `Komodo Edit`_: a sleak, free editor for Mac, Windows and Linux, based on the
4954 more powerful Komodo IDE.
5055
56+ .. _Atom: https://atom.io
5157.. _Sublime Text: http://www.sublimetext.com/
5258.. _Geany: http://www.geany.org/
5359.. _TextMate: http://macromates.com/
@@ -59,25 +65,24 @@ If you'd like our recommendation, try out Sublime Text first.
5965
6066.. tip::
6167
62- Wordpad, TextEdit, Notepad, and Word are **not** suitable text
63- editors.
68+ Wordpad, TextEdit, Notepad, and Word are **not** suitable code editors.
6469
6570What is Python, exactly?
6671========================
6772
6873Ok, so python is this thing called a **programming language**. It takes text that
6974you've written (usually referred to as **code**), turns it into instructions for
7075your computer, and runs those instructions. We'll be learning how to write code
71- to do cool and useful stuff. No longer will you be bound to use others'
72- programs to do things with your computer!
76+ to do cool and useful stuff. No longer will you be bound to use * others'*
77+ programs to do things with your computer - you can make your own !
7378
7479Practically, Python is just another program on your computer. The first thing to
7580learn is how to use and interact with it. There are in fact many ways to do this;
7681the first one to learn is to interact with python's interpreter,
7782using your **operating system's** (OS) console.
7883
7984A **console** (or 'terminal', or 'command prompt') is a *textual* way to
80- interact with your OS, just as the 'desktop', in conjuction with your mouse,
85+ interact with your OS, just as the 'desktop', in conjunction with your mouse,
8186is the *graphical* way to interact your system.
8287
8388Opening a console on Mac OS X
@@ -118,39 +123,39 @@ look like::
118123
119124Window's Command Prompt is not quite as powerful as its counterparts on Linux
120125and OS X, so you might like to start the Python Interpreter (see just below)
121- directly, or using the IDLE program that Python comes with. You can find these
122- in the Start menu.
126+ directly, or using the :program:` IDLE` program that Python comes with.
127+ You can find these in the Start menu.
123128
124129Using Python
125130============
126131
127132The python program that you have installed will by default act as something
128- called an **interpreter**. An interpreter takes commands and runs them as you
129- enter them - very handy for trying things out.
133+ called an **interpreter**. An interpreter takes text commands and runs
134+ them as you enter them - very handy for trying things out.
130135
131136Just type :program:`python` at your console, hit :kbd:`Enter`, and you should
132137enter Python's Interpreter.
133138
134139To find out which version of python you're running,
135- use ``python -V`` to tell you.
140+ instead type ``python -V`` in your console to tell you.
136141
137142Interacting With Python
138143-----------------------
139144
140145After Python opens, it will show you some contextual information similar to this::
141146
142- Python 3.3.2 (default, May 21 2013, 15:40:45)
143- [GCC 4.8.0 20130502 (prerelease) ] on linux
147+ Python 3.5.0 (default, Sep 20 2015, 11:28:25)
148+ [GCC 5.2.0 ] on linux
144149 Type "help", "copyright", "credits" or "license" for more information.
145- >>>
150+ >>>
146151
147152.. note::
148153
149154 The prompt **>>>** on the last line indicates that you are now in an
150155 interactive Python interpeter session, also called the "Python shell".
151156 **This is different from the normal terminal command prompt!**
152157
153- You can now enter some python code . Try::
158+ You can now enter some code for python to run . Try::
154159
155160 print("Hello world")
156161
@@ -167,22 +172,50 @@ An extremely useful command is ``help()``, which enters a help functionality
167172to explore all the stuff python lets you do, right from the interpreter.
168173Press :kbd:`q` to close the help window and return to the Python prompt.
169174
170- To leave the interactive shell, press :kbd:`Ctrl-Z` and then
171- :kbd:`Enter` on Windows, or :kbd:`Ctrl-D` on OS X or Linux. Alternatively,
172- you could also run the python command ``exit()``!
175+ To leave the interactive shell and go back to the console (the *system* shell),
176+ press :kbd:`Ctrl-Z` and then :kbd:`Enter` on Windows, or :kbd:`Ctrl-D` on
177+ OS X or Linux. Alternatively, you could also run the python command ``exit()``!
178+
179+
180+ Exercise
181+ --------
182+
183+ Just above we demonstrated entering a command to figure out some math. Try
184+ some math commands of your own! What operations does python know? Get it
185+ to tell you what 239 and 588 added together, and then squared is.
186+
187+ .. rst-class:: solution
188+
189+ Solution
190+ --------
191+
192+ Here are some ways you might have got the answer:
193+
194+
195+ >>> 239 + 588
196+ 827
197+ >>> 827 * 827
198+ 683929
199+
200+ >>> (239 + 588) * (239 + 588)
201+ 683929
202+
203+ >>> (239 + 588) ** 2
204+ 683929
173205
174206Running Python files
175207--------------------
176208
177209When you have a lot of python code to run, you will want to save it into
178- a file so, for instance, you can modify small parts of it (fix a bug) and
179- re-run it without having to repeatedly re-type the rest.
180- Instead you can save your code to a file and pass a file name to the
181- :program:`python` executable. It will execute that file instead of launching
182- the interactive interpreter.
183-
184- **Let's try that**. Create a file :file:`hello.py` in your current directory
185- with your favorite text editor and write the print command from above. Now
210+ a file, so for instance, you can modify small parts of it (fix a bug) and
211+ re-run the code without having to repeatedly re-type the rest.
212+ Instead of typing commands in one-by-one you can save your code to a
213+ file and pass the file name to the :program:`python` program.
214+ It will execute that file's code instead of
215+ launching its interactive interpreter.
216+
217+ **Let's try that!** Create a file :file:`hello.py` in your current directory
218+ with your favorite code editor and write the print command from above. Now
186219save that file. On Linux or OS X, you can also run ``touch hello.py`` to create
187220an empty file to edit. To run this file with python, it's pretty easy:
188221
@@ -193,7 +226,7 @@ an empty file to edit. To run this file with python, it's pretty easy:
193226.. note::
194227
195228 Make sure you are at your system command prompt, which will have ``$`` or
196- ``>`` at the end, not at python's (which has ``>>>`` instead)!
229+ ``>`` at the end, ** not** at python's (which has ``>>>`` instead)!
197230
198231On Windows you should also be able to double-click the Python file to run it.
199232
@@ -208,8 +241,8 @@ And now we are all set and can get started with turtle!
208241
209242 Not getting "Hello world" but some crazy error about "can't open
210243 file" or "No such file or directory?" Your command line might not be
211- running in the directory you saved the file in. You can use
212- the system command line to change your active directory with the
244+ running in the directory that you saved the file in. You can change
245+ the working directory of your current command line with the
213246 :command:`cd` command, which stands for "change directory". On Windows,
214247 you might want something like::
215248
@@ -222,7 +255,7 @@ And now we are all set and can get started with turtle!
222255 $ cd Desktop/Python_Exercises
223256
224257 This changes to the directory Python_Exercises under the Desktop folder
225- (yours might be somewhere a bit different). If you don't know the location
258+ (yours might be somewhere different). If you don't know the location
226259 of the directory where you saved the file, you can simply drag the
227260 directory to the command line window. If you don't know which
228261 directory your shell is currently running in use :command:`pwd`,
@@ -233,4 +266,4 @@ And now we are all set and can get started with turtle!
233266 When playing around with turtle, avoid naming your file :file:`turtle.py`
234267 --- rather use more appropriate names such as :file:`square.py` or
235268 :file:`rectangle.py`. Otherwise, whenever you refer to ``turtle``, Python
236- will pick up *your* file instead of the standard turtle.
269+ will pick up *your* file instead of the standard Python turtle module .
0 commit comments