you->we, more examples, other fixes · rvlambda/python-tutorial@1298e9a · GitHub
Skip to content

Commit 1298e9a

Browse files
committed
you->we, more examples, other fixes
1 parent 4a77f1b commit 1298e9a

13 files changed

Lines changed: 201 additions & 142 deletions

‎classes.md‎

Lines changed: 20 additions & 18 deletions

‎defining-functions.md‎

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# Defining your own functions
1+
# Defining custom functions
22

3-
It's probably been a while since you read about using functions. [Read
4-
about it again](using-functions.md) if you need to.
3+
It's probably been a while since you read about using functions.
4+
[Read about it again](using-functions.md) if you need to.
55

66
## Why should I use custom functions?
77

@@ -40,7 +40,13 @@ else:
4040
print_box("You didn't enter Python :(")
4141
```
4242

43-
That's nice, but where do we get a `print_box` function like that?
43+
In this tutorial we'll learn to define a `print_box` function
44+
that prints text in a box. We can write the code for printing the
45+
box once, and then use it multiple times anywhere in the program.
46+
47+
Dividing a long program into simple functions also makes the code
48+
easier to work with. If there's a problem with the code we can
49+
test the functions one by one and find the problem easily.
4450

4551
## First functions
4652

@@ -167,7 +173,7 @@ However, modifying a global variable in-place from a function is easy.
167173

168174
This doesn't work if the value is of an immutable type, like string or
169175
integer because immutable values cannot be modified in-place.
170-
Fortunately, Python will tell you if something's wrong.
176+
Fortunately, Python will tell us if something's wrong.
171177

172178
```py
173179
>>> foo = 1
@@ -220,7 +226,7 @@ This function can be called in two ways:
220226
When the function was running it had a local `message` variable
221227
that pointed to `"hi"`. The function printed it twice.
222228

223-
Positional arguments are great for simple things, but if your
229+
Positional arguments are great for simple things, but if our
224230
function takes many positional arguments it may be hard to tell
225231
which argument is which.
226232

@@ -233,7 +239,12 @@ This function can be called in two ways:
233239
>>>
234240
```
235241

236-
Keyword arguments are great when your function needs to take many
242+
The name "keyword argument" is a little bit confusing because
243+
keyword arguments don't actually have anything to do with keywords
244+
(`if`, `else` etc). Keyword arguments are just a way to give names
245+
for our arguments.
246+
247+
Keyword arguments are great when our function needs to take many
237248
arguments, because each argument has a name and it's easy to see
238249
which argument is which.
239250

@@ -334,8 +345,8 @@ need to:
334345
```
335346

336347
The problem is that we have a keyword argument before a positional
337-
argument. Python doesn't allow this. You don't need to worry about
338-
this, because if you accidentally call a function like this you
348+
argument. Python doesn't allow this. We don't need to worry about
349+
this, because if we accidentally call a function like this we
339350
will get an error message.
340351

341352
## Output
@@ -394,11 +405,11 @@ about the `input()` function. It asks the user to enter something, and
394405
then the user enters something and that value is returned. If the input
395406
function would print the value instead of returning it, things like
396407
`name = input("Name: ")` wouldn't work and assigning the result to a
397-
variable would be much more difficult. Printing things is fine when you
398-
know that you'll only need to print the result and you'll never need to
408+
variable would be much more difficult. Printing things is fine when we
409+
know that we'll only need to print the result and we'll never need to
399410
assign it to a variable.
400411

401-
So if our function returns a value we can use it like this:
412+
If our function returns a value we can always print it, like this:
402413

403414
```py
404415
>>> def return_hi():
@@ -409,18 +420,6 @@ hi
409420
>>>
410421
```
411422

412-
If the function prints instead we can call it and just throw away
413-
the None it returns:
414-
415-
```py
416-
>>> def print_hi():
417-
... print("hi")
418-
...
419-
>>> print_hi()
420-
hi
421-
>>>
422-
```
423-
424423
## Examples
425424

426425
Ask yes/no questions.

‎editor-setup.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Setting up an editor for programming
22

33
Python comes with its IDLE, and you can use it in this tutorial. If you
4-
don't like using it for some reason, you need
5-
[PowerShell, command prompt or terminal](installing-python.md) for
6-
trying out things. You also need an editor for writing code that will
4+
don't like using it for some reason, you need [PowerShell, command prompt or
5+
terminal](installing-python.md#if-you-like-working-with-powershell-command-prompt-or-terminal)
6+
for trying out things. You also need an editor for writing code that will
77
be stored in files.
88

99
If you use IDLE as your editor, **it comes with everything set up for
@@ -12,7 +12,7 @@ don't, you probably need to change some settings to make your editor
1212
suitable for Python use.
1313

1414
Do **not** use word processors like Microsoft Word and LibreOffice
15-
Write for programming. They create their own files, but you need plain
15+
Writer for programming. They create their own files, but you need plain
1616
text files for programming.
1717

1818
Start by creating an empty file called `hello.py` and opening it with

‎exceptions.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,10 @@ get when [processing files](files.md), and catching Exception catches
400400
all of these errors. You don't need to remember this tree, running
401401
`help('builtins')` should display a larger tree that this is a part of.
402402

403+
There's also a few exceptions that are not in this tree like SystemExit
404+
and KeyboardInterrupt, but most of the time you shouldn't catch them.
405+
Catching Exception doesn't catch them either.
406+
403407
## Summary
404408

405409
- Exceptions are classes and they can be used just like all other classes.

‎files.md‎

Lines changed: 41 additions & 23 deletions

0 commit comments

Comments
 (0)