@@ -7,74 +7,83 @@ http://python.org/download/
77
88Python 3 is preferable, being the newest version out!
99
10+ .. note ::
11+
12+ On Windows, you'll want to add :program: `Python ` to your path, so it can be found by other
13+ programs. To do this, navigate to your installation directory (:file: `C:\\ Python33\\ `),
14+ open the :file: `Tools `, then :file: `Scripts ` folders, and run the :file: `win_add2path.py `
15+ file by double clicking on it.
16+
1017What is Python, exactly?
1118========================
1219
13- Ok, so python is this thing called a **programming language **. It takes text that
14- you've written (usually referred to as **code **), turns it into instructions for
15- your computer, and runs those instructions. We'll be learning how to write code
16- to do cool and useful stuff. No longer will you be bound to use others'
20+ Ok, so python is this thing called a **programming language **. It takes text that
21+ you've written (usually referred to as **code **), turns it into instructions for
22+ your computer, and runs those instructions. We'll be learning how to write code
23+ to do cool and useful stuff. No longer will you be bound to use others'
1724programs to do things with your computer!
1825
19- Practically, Python is just another program on your computer. The first thing to
20- learn is how to use and interact with it. There are in fact many ways to do this;
21- the first one to learn is to interact with python's interpreter,
26+ Practically, Python is just another program on your computer. The first thing to
27+ learn is how to use and interact with it. There are in fact many ways to do this;
28+ the first one to learn is to interact with python's interpreter,
2229using your **operating system's ** (OS) console.
2330
24- A **console ** (or 'terminal', or 'command prompt') is a *textual * way to interact with
25- your OS, just as the 'desktop', in conjuction with your mouse, is the *graphical *
31+ A **console ** (or 'terminal', or 'command prompt') is a *textual * way to interact with
32+ your OS, just as the 'desktop', in conjuction with your mouse, is the *graphical *
2633way to interact your system.
2734
2835Opening a console on Mac OS X
2936-----------------------------
3037
31- OS X's standard console is a program called Terminal. Open Terminal by
32- navigating to Applications, then Utilities, then double-click the
33- " Terminal" program. You can also easily search for it in the system
38+ OS X's standard console is a program called :program: ` Terminal ` . Open Terminal by
39+ navigating to Applications, then Utilities, then double-click the
40+ :program: ` Terminal ` program. You can also easily search for it in the system
3441search tool in the top right.
3542
36- The command line Terminal is a tool for interacting with your
37- computer. A window will open with a command line prompt message,
43+ The command line Terminal is a tool for interacting with your
44+ computer. A window will open with a command line prompt message,
3845something like this::
3946
4047 mycomputer:~ myusername$
4148
4249Opening a console on Linux
4350--------------------------
4451
45- Different linux distributions (e.g Ubuntu, Fedora, Mint) may have different
46- console programs, usually referred to as a terminal. The exact terminal
47- you start up, and how, can depend on your distribution. On Ubuntu, you will
48- likely want to open Gnome Terminal. It should present a prompt like this::
52+ Different linux distributions (e.g Ubuntu, Fedora, Mint) may have different
53+ console programs, usually referred to as a terminal. The exact terminal
54+ you start up, and how, can depend on your distribution. On Ubuntu, you will
55+ likely want to open :program: ` Gnome Terminal ` . It should present a prompt like this::
4956
5057 myusername@mycomputer:~$
5158
5259Opening a console on Windows
5360----------------------------
5461
55- Window's console is called the Command Prompt, named "cmd.exe". An easy way
56- to get to it is by using the key combination "Windows+R"
57- ('Windows' meaning the windows logo button), which should open a 'Run' dialog.
58- Then simply type :kbd: `cmd ` and hit :kbd: `<Enter> ` / click Ok. It should look like::
62+ Window's console is called the Command Prompt, named :program: `cmd `.
63+ An easy way to get to it is by using the key combination "Windows+R"
64+ ('Windows' meaning the windows logo button), which should open a 'Run' dialog.
65+ Then type :kbd: `cmd ` and hit :kbd: `<Enter> ` or click Ok. You can also search
66+ for it from the start menu. It should look like::
5967
6068 C:\Users\myusername>
6169
62- Window's Command Prompt is not quite as powerful as its counterparts on Linux
63- and OS X, so you might like to start the Python Interpreter (see just below)
64- directly, or using the IDLE program that Python comes with. You can find these
70+ Window's Command Prompt is not quite as powerful as its counterparts on Linux
71+ and OS X, so you might like to start the Python Interpreter (see just below)
72+ directly, or using the IDLE program that Python comes with. You can find these
6573in the start menu.
6674
6775Using Python
6876============
6977
70- The python program that you have installed by default will act as something
71- called an **interpreter **. An interpreter will take commands and run them as you
72- enter them, very handy for trying things out.
78+ The python program that you have installed will by default act as something
79+ called an **interpreter **. An interpreter takes commands and runs them as you
80+ enter them - very handy for trying things out.
7381
74- Just type :program: `python ` at your console, hit :kbd: `<Enter> `, and you should
82+ Just type :program: `python ` at your console, hit :kbd: `<Enter> `, and you should
7583enter Python's Interpreter.
7684
77- To find out which version of python you're running, use :program: `python -V ` to tell you.
85+ To find out which version of python you're running,
86+ use :program: `python -V ` to tell you.
7887
7988Interacting With Python
8089-----------------------
@@ -96,88 +105,89 @@ You can now enter some python code. Try::
96105
97106 print("Hello world")
98107
99- Press :kbd: `<Enter> ` and see what happens. After showing the results, Python
100- will bring you back to the interactive prompt, where you could enter
108+ Press :kbd: `<Enter> ` and see what happens. After showing the results, Python
109+ will bring you back to the interactive prompt, where you could enter
101110another command::
102111
103112 >>> print("Hello world")
104113 Hello world
105- >>>
114+ >>> (1 + 4) * 2
115+ 10
106116
107- An extremely useful command is ``help() ``, which enters a help functionality
117+ An extremely useful command is ``help() ``, which enters a help functionality
108118to explore all the stuff python lets you do, right from the interpreter.
109119
110- To leave the interactive shell, press :kbd: `Ctrl - Z ` and then
111- :kbd: `Enter ` on Windows, or :kbd: `Ctrl - D ` on OS X or Linux. Alternatively,
120+ To leave the interactive shell, press :kbd: `Ctrl - Z ` and then
121+ :kbd: `Enter ` on Windows, or :kbd: `Ctrl - D ` on OS X or Linux. Alternatively,
112122you could also run the python command ``exit() ``!
113123
114124Running Python files
115125--------------------
116126
117- When you have a lot of python code to run, you will want to save it into a file,
118- so you for instance can modify small parts of it (fix a bug) and re-run it,
119- without having to repeatedly re-type the rest.
120- Instead you can save your code to a file and pass a file name to the
121- :program: `python ` executable. It will execute that file instead of launching
127+ When you have a lot of python code to run, you will want to save it into
128+ a file so, for instance, you can modify small parts of it (fix a bug) and
129+ re-run it without having to repeatedly re-type the rest.
130+ Instead you can save your code to a file and pass a file name to the
131+ :program: `python ` executable. It will execute that file instead of launching
122132the interactive interpreter.
123133
134+ **Let's try that **. Create a file :file: `hello.py ` in your current directory
135+ with your favorite text editor and write the print command from above. Now
136+ save-that file. On Linux or OS X, you can also run :kbd: `touch hello.py ` to
137+ create an empty file to edit. To run this file with python, it's pretty easy:
138+
139+ .. code-block :: bash
140+
141+ $ python hello.py
142+
124143 .. note ::
125144
126- Make sure you are at your system command prompt, which will have ``$ `` or
145+ Make sure you are at your system command prompt, which will have ``$ `` or
127146 ``> `` at the end, not at python's (which has ``>>> `` instead)!
128147
129- Let's try that. Create a file :file: `hello.py ` in your current directory with
130- your favorite text editor and paste the print command from above. Now save
131- that file. On Linux or OS X, you can also run :kbd: `touch hello.py ` to create
132- an empty file to edit. To run this file with python, it's pretty easy:
148+ On Windows you should also be able to double-click the Python file to run it.
133149
134- .. code-block :: bash
135-
136- $ python hello.py
150+ When pressing :kbd: `<Enter> ` now, the file is executed and you see the output
151+ as before. But this time, after Python finished executing all commands from
152+ that file it exits back to the system command prompt, instead of going back
153+ to the interactive shell.
137154
138155.. note ::
139156
140- Not getting "Hello world" but some crazy error about "can't open
141- file" or "No such file or directory?" Your command line might not be
142- running in the directory you saved the file in. You can use
143- the system command line to change your active directory with the
144- :command: `cd ` command, which stands for "change directory". On Windows,
157+ Not getting "Hello world" but some crazy error about "can't open
158+ file" or "No such file or directory?" Your command line might not be
159+ running in the directory you saved the file in. You can use
160+ the system command line to change your active directory with the
161+ :command: `cd ` command, which stands for "change directory". On Windows,
145162 you might want something like::
146163
147- $ cd Desktop\Python_Exercises
164+ > cd Desktop\Python_Exercises
148165
149166 On Linux or OS X, you might want something like::
150167
151168 $ cd Desktop/Python_Exercises
152169
153- This changes to the directory Python_Exercises under the Desktop folder
154- (yours might be somewhere a bit different). If you don't know the location
155- of the directory where you saved the file, you can simply drag the
156- directory to the command line window. If you don't know which
157- directory your shell is currently running in use :command: `pwd `,
170+ This changes to the directory Python_Exercises under the Desktop folder
171+ (yours might be somewhere a bit different). If you don't know the location
172+ of the directory where you saved the file, you can simply drag the
173+ directory to the command line window. If you don't know which
174+ directory your shell is currently running in use :command: `pwd `,
158175 which stands for "print working directory".
159176
160- On Windows you should also be able to double-click the Python file to run it.
161-
162- When pressing :kbd: `<Enter> ` now, the file is executed and you see the output
163- as before. But this time, after Python finished executing all commands from
164- that file it exits back to the system command prompt, instead of going back
165- to the interactive shell.
166-
167177.. tip ::
168178
169- Wordpad, TextEdit, Notepad, and Word are **not ** suitable text
170- editors. If you are unsure whether you already have a usable
171- editor, you might want to download and install `Sublime Text
172- <http://www.sublimetext.com/> `_. Code editors like this
179+ Wordpad, TextEdit, Notepad, and Word are **not ** suitable text
180+ editors. If you are unsure whether you already have a usable
181+ editor, you might want to download and install `Sublime Text
182+ <http://www.sublimetext.com/> `_. Code editors like this
173183 can also help you with formatting, running and debugging your code.
174184
175185And now we are all set and can get started with turtle!
176186
177- .. important ::
187+ .. warning ::
178188
179- When playing around with turtle, avoid naming your file :file: `turtle.py `
180- --- rather use more appropriate names such as :file: `square.py ` or
181- :file: `rectangle.py `. Otherwise, whenever you refer to ``turtle ``, Python
189+ When playing around with turtle, avoid naming your file :file: `turtle.py `
190+ --- rather use more appropriate names such as :file: `square.py ` or
191+ :file: `rectangle.py `. Otherwise, whenever you refer to ``turtle ``, Python
182192 will pick up *your * file instead of the standard turtle.
183193
0 commit comments