Skip to content

Commit c8e3a07

Browse files
committed
running strip.py
1 parent 375a8f6 commit c8e3a07

21 files changed

+337
-337
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The tutorial consists of two sections:
2727

2828
### Basics
2929

30-
This section will get you started with using Python and you'll be able
30+
This section will get you started with using Python and you'll be able
3131
to learn more about whatever you want after studying it.
3232

3333
1. [What is programming?](basics/what-is-programming.md)
@@ -51,14 +51,14 @@ to learn more about whatever you want after studying it.
5151

5252
### Advanced
5353

54-
If you want to learn more advanced techniques, you can also read this
55-
section. Most of the techniques explained here are great when you're
56-
working on a large project, and your code would be really repetitive
54+
If you want to learn more advanced techniques, you can also read this
55+
section. Most of the techniques explained here are great when you're
56+
working on a large project, and your code would be really repetitive
5757
without these things.
5858

59-
You can experient with these things freely, but please **don't use these
60-
techniques just because you know how to use them.** Prefer the simple
61-
techniques from the Basics part instead when possible. Simple is better
59+
You can experient with these things freely, but please **don't use these
60+
techniques just because you know how to use them.** Prefer the simple
61+
techniques from the Basics part instead when possible. Simple is better
6262
than complex.
6363

6464
1. [Advanced stuff with functions](advanced/functions.md)

advanced/iterators.md

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,33 @@ So far we have used for loops with many different kinds of things.
55
```py
66
>>> for name in ['theelous3', 'RubyPinch', 'go|dfish']:
77
... print(name)
8-
...
8+
...
99
theelous3
1010
RubyPinch
1111
go|dfish
1212
>>> for letter in 'abc':
1313
... print(letter)
14-
...
14+
...
1515
a
1616
b
1717
c
18-
>>>
18+
>>>
1919
```
2020

21-
For looping over something is one way to **iterate** over it. Some other
22-
things also iterate, for example, `' '.join(['a', 'b', 'c'])` iterates
23-
over the list `['a', 'b', 'c']`. If we can for loop over something, then
24-
that something is **iterable**. For example, strings and lists are
21+
For looping over something is one way to **iterate** over it. Some other
22+
things also iterate, for example, `' '.join(['a', 'b', 'c'])` iterates
23+
over the list `['a', 'b', 'c']`. If we can for loop over something, then
24+
that something is **iterable**. For example, strings and lists are
2525
iterable, but integers and floats are not.
2626

2727
```py
2828
>>> for thing in 123:
2929
... print(thing)
30-
...
30+
...
3131
Traceback (most recent call last):
3232
File "<stdin>", line 1, in <module>
3333
TypeError: 'int' object is not iterable
34-
>>>
34+
>>>
3535
```
3636

3737
## Iterators
@@ -42,36 +42,36 @@ Lists and strings don't change when we iterate over them.
4242
>>> word = 'hi'
4343
>>> for character in word:
4444
... print(character)
45-
...
45+
...
4646
h
4747
i
4848
>>> word
4949
'hello'
50-
>>>
50+
>>>
5151
```
5252

53-
We can also iterate over [files](../basics/files.md), but they change
54-
when we do that. They remember their position, so if we iterate over
53+
We can also iterate over [files](../basics/files.md), but they change
54+
when we do that. They remember their position, so if we iterate over
5555
them twice we get the content once only.
5656

5757
```py
5858
>>> with open('test.txt', 'w') as f:
5959
... print("one", file=f)
6060
... print("two", file=f)
61-
...
61+
...
6262
>>> a = []
6363
>>> b = []
6464
>>> with open('test.txt', 'r') as f:
6565
... for line in f:
6666
... a.append(line)
6767
... for line in f:
6868
... b.append(line)
69-
...
69+
...
7070
>>> a
7171
['one\n', 'two\n']
7272
>>> b
7373
[]
74-
>>>
74+
>>>
7575
```
7676

7777
We have also used [enumerate](../basics/trey-hunner-zip-and-enumerate.md)
@@ -81,21 +81,21 @@ before, and it actually remembers its position also:
8181
>>> e = enumerate('hello')
8282
>>> for pair in e:
8383
... print(pair)
84-
...
84+
...
8585
(0, 'h')
8686
(1, 'e')
8787
(2, 'l')
8888
(3, 'l')
8989
(4, 'o')
9090
>>> for pair in e:
9191
... print(pair)
92-
...
93-
>>>
92+
...
93+
>>>
9494
```
9595

96-
Iterators are **iterables that remember their position**. For example,
97-
`open('test.txt', 'r')` and `enumerate('hello')` are iterators.
98-
Iterators can only be used once, so we need to create a new iterator if
96+
Iterators are **iterables that remember their position**. For example,
97+
`open('test.txt', 'r')` and `enumerate('hello')` are iterators.
98+
Iterators can only be used once, so we need to create a new iterator if
9999
we want to do another for loop.
100100

101101
Here's a picture that hopefully explains this better:
@@ -104,8 +104,8 @@ Here's a picture that hopefully explains this better:
104104

105105
## Iterating manually
106106

107-
Iterators have a magic method called `__next__`, and there's a built-in
108-
function called `next()` for calling that. Calling `next()` on an
107+
Iterators have a magic method called `__next__`, and there's a built-in
108+
function called `next()` for calling that. Calling `next()` on an
109109
iterator gets the next value and moves it forward. Like this:
110110

111111
```py
@@ -116,7 +116,7 @@ iterator gets the next value and moves it forward. Like this:
116116
(1, 'b')
117117
>>> e.__next__()
118118
(2, 'c')
119-
>>>
119+
>>>
120120
```
121121

122122
There's also a built-in `next()` function that does the same thing:
@@ -129,26 +129,26 @@ There's also a built-in `next()` function that does the same thing:
129129
(1, 'b')
130130
>>> next(e)
131131
(2, 'c')
132-
>>>
132+
>>>
133133
```
134134

135-
Here `e` remembers its position, and every time we call `next(e)` it
136-
gives us the next element and moves forward. When it has no more values
135+
Here `e` remembers its position, and every time we call `next(e)` it
136+
gives us the next element and moves forward. When it has no more values
137137
to give us, calling `next(e)` raises a StopIteration:
138138

139139
```py
140140
>>> next(e)
141141
Traceback (most recent call last):
142142
File "<stdin>", line 1, in <module>
143143
StopIteration
144-
>>>
144+
>>>
145145
```
146146

147-
There is usually not a good way to check if the iterator is at the end,
148-
and it's best to just try to get an value from it and catch
147+
There is usually not a good way to check if the iterator is at the end,
148+
and it's best to just try to get an value from it and catch
149149
StopIteration.
150150

151-
This is actually what for looping over an iterator does. For example,
151+
This is actually what for looping over an iterator does. For example,
152152
this code...
153153

154154
```py
@@ -170,24 +170,24 @@ while True:
170170
print(pair)
171171
```
172172

173-
The for loop version is much simpler to write and I wrote the while loop
173+
The for loop version is much simpler to write and I wrote the while loop
174174
version just to explain what the for loop does.
175175

176176
## Converting to iterators
177177

178-
Now we know what iterating over an iterator does. But how about
179-
iterating over a list or a string? They are not iterators, so we can't
178+
Now we know what iterating over an iterator does. But how about
179+
iterating over a list or a string? They are not iterators, so we can't
180180
call `next()` on them:
181181

182182
```py
183183
>>> next('abc')
184184
Traceback (most recent call last):
185185
File "<stdin>", line 1, in <module>
186186
TypeError: 'str' object is not an iterator
187-
>>>
187+
>>>
188188
```
189189

190-
There's a built-in function called `iter()` that converts anything
190+
There's a built-in function called `iter()` that converts anything
191191
iterable to an iterator.
192192

193193
```py
@@ -204,7 +204,7 @@ iterable to an iterator.
204204
Traceback (most recent call last):
205205
File "<stdin>", line 1, in <module>
206206
StopIteration
207-
>>>
207+
>>>
208208
```
209209

210210
Calling `iter()` on anything non-iterable gives us an error.
@@ -214,17 +214,17 @@ Calling `iter()` on anything non-iterable gives us an error.
214214
Traceback (most recent call last):
215215
File "<stdin>", line 1, in <module>
216216
TypeError: 'int' object is not iterable
217-
>>>
217+
>>>
218218
```
219219

220-
If we try to convert an iterator to an iterator using `iter()` we just
220+
If we try to convert an iterator to an iterator using `iter()` we just
221221
get back the same iterator.
222222

223223
```py
224224
>>> e = enumerate('abc')
225225
>>> iter(e) is e
226226
True
227-
>>>
227+
>>>
228228
```
229229

230230
So code like this...
@@ -248,8 +248,8 @@ while True:
248248

249249
## Custom iterables
250250

251-
Implementing a custom iterator is easy. All we need to do is to define a
252-
`__next__` method that gets the next element, and an `__iter__` method
251+
Implementing a custom iterator is easy. All we need to do is to define a
252+
`__next__` method that gets the next element, and an `__iter__` method
253253
that returns the iterator itself. For example, here's an iterator that
254254
behaves like `iter([1, 2, 3])`:
255255

advanced/magicmethods.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ follow one of these styles:
215215
## Other magic methods
216216

217217
There are many more magic methods, and I don't see any reason to list
218-
them all here. [The official
218+
them all here. [The official
219219
documentation](https://docs.python.org/3/reference/datamodel.html) has
220220
more information about magic methods if you need it. We'll go through
221221
using the most important magic methods in the rest of this tutorial, so

basics/answers.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ isn't exactly like mine but it works just fine it's ok, and you can
117117
2. If we have a look at `help(str.upper)` it looks like this:
118118

119119
S.upper() -> str
120-
120+
121121
Return a copy of S converted to uppercase.
122122

123123
We have two problems. First of all, the broken code uses
@@ -324,11 +324,11 @@ isn't exactly like mine but it works just fine it's ok, and you can
324324
```py
325325
>>> for pair in zip('ABC', 'abc'):
326326
... print(pair)
327-
...
327+
...
328328
('A', 'a')
329329
('B', 'b')
330330
('C', 'c')
331-
>>>
331+
>>>
332332
```
333333

334334
Great, it works just like it works with lists. Now let's create
@@ -389,7 +389,7 @@ isn't exactly like mine but it works just fine it's ok, and you can
389389
def ask_name():
390390
name = input("Enter your name: ")
391391
return name
392-
392+
393393
print("Your name is", ask_name())
394394
```
395395

@@ -403,7 +403,7 @@ isn't exactly like mine but it works just fine it's ok, and you can
403403
```py
404404
def get_greeting():
405405
return "Hello World!"
406-
406+
407407
print(get_greeting())
408408
```
409409

@@ -414,7 +414,7 @@ isn't exactly like mine but it works just fine it's ok, and you can
414414
```py
415415
>>> greet("World")
416416
Hello World
417-
>>>
417+
>>>
418418
```
419419

420420
But it also returns None because we don't tell it to return anything else.
@@ -424,7 +424,7 @@ isn't exactly like mine but it works just fine it's ok, and you can
424424
Hello World
425425
>>> print(return_value)
426426
None
427-
>>>
427+
>>>
428428
```
429429

430430
This code from the exercise does the same thing as the code above
@@ -434,7 +434,7 @@ isn't exactly like mine but it works just fine it's ok, and you can
434434
>>> print(greet("World"))
435435
Hello World
436436
None
437-
>>>
437+
>>>
438438
```
439439

440440
***

0 commit comments

Comments
 (0)