Commit 0715921e authored by Renato Alves's avatar Renato Alves 🌱

Merge branch 'syntax_elements_and' into 'master'

Fine tune / Fix typos in "Syntax Elements & Powerful Functions"

See merge request grp-bio-it-workshops/intermediate-python!36
parents a6a599fc c2e10b20
......@@ -433,7 +433,7 @@ I have 10 cherries
{: .output}
Notice that we didn't have to use `str()` around `count`.
Since we use `%s` as placeholder, we implicitly request that the value in converted
Since we use `%s` as placeholder, we implicitly request that the value is converted
to its string representation.
You can find information about alternative placeholders and syntax in the [old formatting style python documentation][old-formatting].
......@@ -615,7 +615,7 @@ ZeroDivisionError: division by zero
~~~
{: .output}
Since dividing by zero is [*mathematically undefined*][https://en.wikipedia.org/wiki/Division_by_zero]
Since dividing by zero is [*mathematically undefined*](https://en.wikipedia.org/wiki/Division_by_zero)
we have to avoid this operation or deal with the consequences.
One possibility is to do:
~~~
......@@ -656,7 +656,7 @@ But wait, there's more!
8 raise
9 except ZeroDivisionError:
10 print("We cannot divide by zero")
11 print("But we want to stop the exception and turn in into a ValueError")
11 print("But we want to stop the exception and turn it into a ValueError")
12 print("which external code knows how to handle")
13 raise ValueError("complex_function tried to divide by zero")
14 else:
......@@ -1031,7 +1031,7 @@ Positional arguments: (4, 3, 3, 5) - Keyword arguments: {'name': 'John', 'age':
> which can be used to add items to a shopping cart
> ~~~
> fruit_cart = ["apples", "oranges"]
> new_fruit_cart = add_to_cart("bananas", mycart)
> new_fruit_cart = add_to_cart("bananas", fruit_cart)
> print(new_fruit_cart)
> # This prints ["apples", "oranges", "bananas"]
> ~~~
......@@ -1111,7 +1111,7 @@ Or have terabytes of sequencing data to go through.
As you start loading this data and storing it in any of the containers we've seen
up to now (`list`, `dict`, `set`), you'll soon realize that they are too big
or there are too many to keep in memory at all times.
A possible solution is to transform your some of your functions into generators.
A possible solution is to transform some of your functions into generators.
Generators, as you may guess from the name, create data as they go.
They further contrast with functions by only generating as many results as necessary
......@@ -1256,7 +1256,7 @@ Using `.send()` will cause the generator to receive a value and iterate to the n
## Comprehensions
Comprehensions are a more succinct form of loop with an accumulator.
Comprehensions are a more succinct form of a loop with an accumulator.
While succinct and powerful, one should use this syntax with moderation,
as complex comprehensions can sacrifice readability in favor of compactness.
......@@ -1318,7 +1318,7 @@ The syntax for each is:
{: .callout}
If you want to read from or write to a file in Python you would typically use the
`open()` function, which returns a handle to the fileyou specified together with one of a few modes.
`open()` function, which returns a handle to the file you specified together with one of a few modes.
If reading text `rt`, if writing text `wt`, if reading binary `rb` and similarly if writing binary `wb`.
You may also add `U` to the mode string (e.g. `mode='rtU') to
activate universal line end mode, which ensures files are read the same
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment