Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Convention says that numbers should be named in lower case, with whole words sep
If you want to learn more about Python naming conventions look at [PEP8](https://www.python.org/dev/peps/pep-0008/#naming-conventions) during a break.
{{% /notice %}}

Because Python is a dynamic language and you don't have type hints to explain what's stored inside a variable while reading code, you should do your best naming your variables to describe what is stored inside of them.
Because Python is a dynamic language and you don't have type hints to explain what's stored inside a variable while reading a code, you should do your best naming your variables to describe what is stored inside of them.

It's ok to be _verbose_. For example, `n` is a poor variable name, while `numbers` is a better one. If you're storing a collection of items, name your variable as a plural.

Expand All @@ -84,7 +84,7 @@ If you notice your program behaving oddly and you can't find the source of the b

## Types

Python has a very easy way of determining the type of something. It's the `type()` function.
Python has a very easy way of determining the type of something, with the `type()` function.

```python
>>> num = 42
Expand All @@ -101,4 +101,4 @@ If you try to examine a variable on the REPL that's been set to `None`, you won'
```python
>>> x = None
>>> x
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This is the recipe for defining a Python function:
1. a name for the function
1. `(`: opening parenthesis
1. (optional) the **names** of one or more arguments, separated with `,`
1. (optional) the **names** and **values** of one or more default arguments, separated with (`,`) *note: we'll see these in the next section*
1. (optional) the **names** and **values** of one or more default arguments, separated with (`,`) *note: we'll see this in the next section*
1. `)` closing parenthesis
1. `:` a colon

Expand Down Expand Up @@ -65,10 +65,10 @@ SyntaxError: invalid syntax

The recipe for function contents:

1. a new line
1. indentation (press tab on your keyboard)
1. one or more lines
1. (optional) a `return` statement
1. a new line.
1. indentation (press tab on your keyboard).
1. one or more lines.
1. (optional) a `return` statement.

#### `return` statement

Expand Down Expand Up @@ -204,4 +204,4 @@ Let's try it now.
8
```

The variable `new_number` now contains the result of running our `add_numbers` function with our arguments `3` and `8`.
The variable `new_number` now contains the result of running our `add_numbers` function with our arguments `3` and `8`.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Why? Because it won't work like you'd expect it to.

If you need to use a mutable type, like a `list` as a default, use a *marker* instead. We'll cover this technique when we talk about `list`s in the next chapter.

In Python, default arguments are evaluated only once -- when the unction is defined. Not each time the function is called. That means if you use a value that can be changed, it won't behave like you'd expect it to.
In Python, default arguments are evaluated only once -- when the function is defined. Not each time the function is called. That means if you use a value that can be changed, it won't behave like you'd expect it to.

### Naming Functions and Arguments

Expand All @@ -189,4 +189,4 @@ For example, I'd expect a variable called `name` to be a single string, and a va

{{% notice tip %}}
A great resource to help you figure out the best naming conventions to use in your production Python code is a talk by Brandon Rhodes, called ["The Naming of Ducks: Where Dynamic Types Meet Smart Conventions"](https://www.youtube.com/watch?v=YklKUuDpX5c).
{{% /notice %}}
{{% /notice %}}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pre: "<b>⭐️ </b>"

## Functions

Let's try creating a basic function. Use tab to intent the second line, and press enter on an empty line to finish the function.
Let's try creating a basic function. Use tab to indent the second line, and press enter on an empty line to finish the function.

```python
>>> def add_numbers(x, y):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ We'll see `TypeError: 'tuple' object does not support item assignment` if we try

### `tuple` unpacking.

Sounds like a lot of work for not a lot of benefit, right? Not so. `tuple`s are great when you depend on your data staying unchanged. Because of this guarantee, we can use `tuples` in other types of containers like `set`s and `dict`ionaries.
Sounds like a lot of work for not a lot of benefit, right? Not so. `tuple`s are great when you depend on your data staying unchanged. Because of this guarantee, we can use `tuples` in other types of containers like `set`s and `dictionaries`.

It's also a great way to quickly consolidate information.

Expand Down Expand Up @@ -121,4 +121,4 @@ You can return tuples from functions, and use unpacking.
200
>>> value
'OK'
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Sets are a datatype that allows you to store other **immutable** types in an uns
| creation | `set()` for an empty set (`{}` makes an empty `dict`) and `{1, 2, 3}` for a set with items in it |
| search methods | `item in my_set` |
| search speed | Searching for an item in a large set is very fast. |
| common methods | `my_set.add(item)`, `my_set.discard(item)` to remove the item if it's present, `my_set.update(other_set)` |
| common methods | `my_set.add(item)`,to add an item to a set , `my_set.discard(item)` to remove the item if it's present, `my_set.update(other_set)` |
| order preserved? | **No**. Items *can't* be accessed by index. |
| mutable? | **Yes**. Can add to or remove from `set`s. |
| in-place sortable? | **No**, because items aren't ordered. |
Expand Down