Skip to content

Commit 874e7f6

Browse files
timhoffmronreiter
authored andcommitted
Adapt whitespace to conform with PEP-8 recommendations
1 parent 7fa40b7 commit 874e7f6

File tree

6 files changed

+33
-33
lines changed

6 files changed

+33
-33
lines changed

tutorials/learnpython.org/en/Generators.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Here is a simple example of a generator function which returns 7 random integers
1717
yield random.randint(1, 40)
1818
1919
# returns a 7th number between 1 and 15
20-
yield random.randint(1,15)
20+
yield random.randint(1, 15)
2121
2222
for random_number in lottery():
2323
print("And the next number is... %d!" %(random_number))
@@ -33,7 +33,7 @@ Hint: Can you use only two variables in the generator function? Remember that as
3333
a = 1
3434
b = 2
3535
a, b = b, a
36-
print(a,b)
36+
print(a, b)
3737

3838
will simultaneously switch the values of a and b.
3939

tutorials/learnpython.org/en/Input and Output.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ this is especially used to input integers. The advantage of input() over raw_inp
3131
Here we make use split() and map() functions
3232

3333
#give two integers in first line and more than two integers in third line
34-
a,b=map(int,raw_input().split()
35-
array=raw_input().split()
36-
sum=0
34+
a, b = map(int, raw_input().split())
35+
array = raw_input().split()
36+
sum = 0
3737
for each in array:
38-
sum=sum+int(each)
39-
print a,b,sum #prints first two integers from first line and sum of integers of second line
38+
sum = sum + int(each)
39+
print(a, b, sum) # prints first two integers from first line and sum of integers of second line
4040

4141
###Output formatting
4242
You might have already noticed that print statement automatically inserts a new line. The use of comma like in the above code prints the values in a single line separated by a space.
4343
The sys module provides various functions for output formatting but here we learn how to use basic knowledge of formatting to output in our required way. Lets see a few examples to learn output formatting
4444

45-
a=5
46-
b=0.63
47-
c="hello"
48-
print "a is : %d, b is %0.4f,c is %s" %(a,b,c)
45+
a = 5
46+
b = 0.63
47+
c = "hello"
48+
print "a is : %d, b is %0.4f,c is %s" % (a,b,c)
4949

5050
The output must be self explanatory.

tutorials/learnpython.org/en/Map, Filter, Reduce.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,25 @@ Python already blesses us with the ```round()``` built-in function that takes tw
5151

5252
circle_areas = [3.56773, 5.57668, 4.00914, 56.24241, 9.01344, 32.00013]
5353

54-
result = list(map(round, circle_areas, range(1,7)))
54+
result = list(map(round, circle_areas, range(1, 7)))
5555

5656
print(result)
5757

5858
See the beauty of ```map()```? Can you imagine the flexibility this evokes?
5959

60-
The ```range(1,7)``` function acts as the second argument to the ```round``` function (the number of required decimal places per iteration). So as ```map``` iterates through ```circle_areas```, during the first iteration, the first element of ```circle_areas```, ```3.56773``` is passed along with the first element of ```range(1,7)```, ```1``` to ```round```, making it effectively become ```round(3.56773, 1)```. During the second iteration, the second element of ```circle_areas```, ```5.57668``` along with the second element of ```range(1,7)```, ```2``` is passed to ```round``` making it translate to ```round(5.57668, 2)```. This happens until the end of the ```circle_areas``` list is reached.
60+
The ```range(1, 7)``` function acts as the second argument to the ```round``` function (the number of required decimal places per iteration). So as ```map``` iterates through ```circle_areas```, during the first iteration, the first element of ```circle_areas```, ```3.56773``` is passed along with the first element of ```range(1,7)```, ```1``` to ```round```, making it effectively become ```round(3.56773, 1)```. During the second iteration, the second element of ```circle_areas```, ```5.57668``` along with the second element of ```range(1,7)```, ```2``` is passed to ```round``` making it translate to ```round(5.57668, 2)```. This happens until the end of the ```circle_areas``` list is reached.
6161

62-
I'm sure you're wondering: "What if I pass in an iterable less than or more than the length of the first iterable? That is, what if I pass ```range(1,3)``` or ```range(1, 9999)``` as the second iterable in the above function". And the answer is simple: nothing! Okay, that's not true. "Nothing" happens in the sense that the ```map()``` function will not raise any exception, it will simply iterate over the elements until it can't find a second argument to the function, at which point it simply stops and returns the result.
62+
I'm sure you're wondering: "What if I pass in an iterable less than or more than the length of the first iterable? That is, what if I pass ```range(1, 3)``` or ```range(1, 9999)``` as the second iterable in the above function". And the answer is simple: nothing! Okay, that's not true. "Nothing" happens in the sense that the ```map()``` function will not raise any exception, it will simply iterate over the elements until it can't find a second argument to the function, at which point it simply stops and returns the result.
6363

64-
So, for example, if you evaluate ```result = list(map(round, circle_areas, range(1,3)))```, you won't get any error even as the length of ```circle_areas``` and the length of ```range(1,3)``` differ. Instead, this is what Python does: It takes the first element of ```circle_areas``` and the first element of ```range(1,3)``` and passes it to ```round```. ```round``` evaluates it then saves the result. Then it goes on to the second iteration, second element of ```circle_areas``` and second element of ```range(1,3)```, ```round``` saves it again. Now, in the third iteration (```circle_areas``` has a third element), Python takes the third element of ```circle_areas``` and then tries to take the third element of ```range(1,3)``` but since ```range(1,3)``` does not have a third element, Python simply stops and returns the result, which in this case would simply be ```[3.6, 5.58]```.
64+
So, for example, if you evaluate ```result = list(map(round, circle_areas, range(1, 3)))```, you won't get any error even as the length of ```circle_areas``` and the length of ```range(1, 3)``` differ. Instead, this is what Python does: It takes the first element of ```circle_areas``` and the first element of ```range(1,3)``` and passes it to ```round```. ```round``` evaluates it then saves the result. Then it goes on to the second iteration, second element of ```circle_areas``` and second element of ```range(1,3)```, ```round``` saves it again. Now, in the third iteration (```circle_areas``` has a third element), Python takes the third element of ```circle_areas``` and then tries to take the third element of ```range(1,3)``` but since ```range(1,3)``` does not have a third element, Python simply stops and returns the result, which in this case would simply be ```[3.6, 5.58]```.
6565

6666
Go ahead, try it.
6767

6868
# Python 3
6969

7070
circle_areas = [3.56773, 5.57668, 4.00914, 56.24241, 9.01344, 32.00013]
7171

72-
result = list(map(round, circle_areas, range(1,3)))
72+
result = list(map(round, circle_areas, range(1, 3)))
7373

7474
print(result)
7575

@@ -81,7 +81,7 @@ To consolidate our knowledge of the ```map()``` function, we are going to use it
8181
# Python 3
8282

8383
my_strings = ['a', 'b', 'c', 'd', 'e']
84-
my_numbers = [1,2,3,4,5]
84+
my_numbers = [1, 2, 3, 4, 5]
8585

8686
results = list(zip(my_strings, my_numbers))
8787

@@ -94,7 +94,7 @@ Onto our own custom ```zip()``` function!
9494
# Python 3
9595

9696
my_strings = ['a', 'b', 'c', 'd', 'e']
97-
my_numbers = [1,2,3,4,5]
97+
my_numbers = [1, 2, 3, 4, 5]
9898

9999
results = list(map(lambda x, y: (x, y), my_strings, my_numbers))
100100

tutorials/learnpython.org/en/Multiple Function Arguments.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ It is possible to declare functions which receive a variable number of arguments
1515
print("Third: %s" % third)
1616
print("And all the rest... %s" % list(therest))
1717

18-
The "therest" variable is a list of variables, which receives all arguments which were given to the "foo" function after the first 3 arguments. So calling `foo(1,2,3,4,5)` will print out:
18+
The "therest" variable is a list of variables, which receives all arguments which were given to the "foo" function after the first 3 arguments. So calling `foo(1, 2, 3, 4, 5)` will print out:
1919

2020
def foo(first, second, third, *therest):
2121
print("First: %s" %(first))
2222
print("Second: %s" %(second))
2323
print("Third: %s" %(third))
2424
print("And all the rest... %s" %(list(therest)))
2525

26-
foo(1,2,3,4,5)
26+
foo(1, 2, 3, 4, 5)
2727

2828
It is also possible to send functions arguments by keyword, so that the order of the argument does not matter, using the following syntax. The following code yields the following output:
2929
```The sum is: 6
@@ -62,13 +62,13 @@ def bar(a, b, c):
6262
6363
6464
# test code
65-
if foo(1,2,3,4) == 1:
65+
if foo(1, 2, 3, 4) == 1:
6666
print("Good.")
67-
if foo(1,2,3,4,5) == 2:
67+
if foo(1, 2, 3, 4, 5) == 2:
6868
print("Better.")
69-
if bar(1,2,3,magicnumber = 6) == False:
69+
if bar(1, 2, 3, magicnumber=6) == False:
7070
print("Great.")
71-
if bar(1,2,3,magicnumber = 7) == True:
71+
if bar(1, 2, 3, magicnumber=7) == True:
7272
print("Awesome!")
7373
7474
Expected Output
@@ -91,11 +91,11 @@ def bar(a, b, c, **kwargs):
9191
9292
9393
# test code
94-
if foo(1,2,3,4) == 1:
94+
if foo(1, 2, 3, 4) == 1:
9595
print("Good.")
96-
if foo(1,2,3,4,5) == 2:
96+
if foo(1, 2, 3, 4, 5) == 2:
9797
print("Better.")
98-
if bar(1,2,3,magicnumber = 6) == False:
98+
if bar(1, 2, 3, magicnumber=6) == False:
9999
print("Great.")
100-
if bar(1,2,3,magicnumber = 7) == True:
100+
if bar(1, 2, 3, magicnumber=7) == True:
101101
print("Awesome!")

tutorials/learnpython.org/en/Partial functions.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ This code will return 8.
1313

1414
from functools import partial
1515

16-
def multiply(x,y):
16+
def multiply(x, y):
1717
return x * y
1818

1919
# create a new function that multiplies by 2
20-
dbl = partial(multiply,2)
20+
dbl = partial(multiply, 2)
2121
print(dbl(4))
2222

2323
An important note: the default values will start replacing variables from the left. The 2 will replace x.
@@ -32,7 +32,7 @@ Tutorial Code
3232
-------------
3333
#Following is the exercise, function provided:
3434
from functools import partial
35-
def func(u,v,w,x):
35+
def func(u, v, w, x):
3636
return u*4 + v*3 + w*2 + x
3737
#Enter your code here to create and print with your partial function
3838

@@ -45,7 +45,7 @@ success_msg('Good job!')
4545
Solution
4646
--------
4747
from functools import partial
48-
def func(u,v,w,x):
48+
def func(u, v, w, x):
4949
return u*4 + v*3 + w*2 + x
5050

5151
p = partial(func,5,6,7)

tutorials/learnpython.org/en/Variables and Types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Simple operators can be executed on numbers and strings:
5151
Assignments can be done on more than one variable "simultaneously" on the same line like this
5252

5353
a, b = 3, 4
54-
print(a,b)
54+
print(a, b)
5555

5656
Mixing operators between numbers and strings is not supported:
5757

0 commit comments

Comments
 (0)