From 60c2d7817099e25c2b801dcf28fa71d5088cbba1 Mon Sep 17 00:00:00 2001 From: Akuli Date: Fri, 5 Jan 2018 22:42:40 +0200 Subject: [PATCH] fixes --- basics/answers.md | 12 ++++++------ basics/defining-functions.md | 22 +++++++--------------- getting-help.md | 2 +- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/basics/answers.md b/basics/answers.md index c4e3b41..de739c3 100644 --- a/basics/answers.md +++ b/basics/answers.md @@ -66,7 +66,7 @@ isn't exactly like mine but it works just fine it's ok, and you can ```python no_space = input("Enter a word: ") yes_space = no_space + " " - print(yes_space * 999 + no_space) + print(yes_space*999 + no_space) ``` 5. Like this: @@ -79,12 +79,12 @@ isn't exactly like mine but it works just fine it's ok, and you can ``` 6. We can compare the word against an empty string (`""` or `''`) to - check if it's empty. In this example, the password is "s3cr3t". + check if it's empty. In this example, the password is "seKr3t". ```python word = input("Enter your password: ") - if word == "s3cr3t": + if word == "seKr3t": print("Welcome!") elif word == "": print("You didn't enter anything.") @@ -92,8 +92,7 @@ isn't exactly like mine but it works just fine it's ok, and you can print("Access denied.") ``` - This is not a good way to ask a password from the user because the - password isn't hidden in any way, but this is just an example. + Again, this is not a good way to ask a real password from the user. ## Handy stuff: Strings @@ -219,7 +218,8 @@ isn't exactly like mine but it works just fine it's ok, and you can problems and solutions: - `namelist` is None. It should be `namelist.extend('theelous3')`, - not `namelist = namelist.extend('theelous3')`. + not `namelist = namelist.extend('theelous3')`. See [this + thing](using-functions.md#return-values). - Now the namelist is like `['wub_wub', ..., 't', 'h', 'e', 'e', ...]`. Python treated `'theelous3'` like a list so it added each of its characters to `namelist`. We can use `namelist.append('theelous3')` diff --git a/basics/defining-functions.md b/basics/defining-functions.md index cee0d60..faba43f 100644 --- a/basics/defining-functions.md +++ b/basics/defining-functions.md @@ -177,20 +177,16 @@ However, modifying a global variable in-place from a function is easy. >>> ``` -This doesn't work if the value is of an immutable type, like string or -integer because immutable values cannot be modified in-place. -Fortunately, Python will tell us if something's wrong. +This only works for changing in-place, we cannot assign a new value to +the variable. ```python ->>> thing = 1 ->>> def stuff(): -... thing += 1 +>>> def set_stuff_to_something_new(): +... stuff = ['more local stuff'] ... ->>> stuff() -Traceback (most recent call last): - File "", line 1, in - File "", line 2, in stuff -UnboundLocalError: local variable 'thing' referenced before assignment +>>> set_stuff_to_something_new() +>>> stuff +['global stuff', 'local stuff'] >>> ``` @@ -262,10 +258,6 @@ This function can be called in two ways: because `message = "hi"` and `some_function(message="hi")` do two completely different things. -Personally, I would use this function with a positional argument. It -only takes one argument, so I don't need to worry about which argument -is which. - Now it's time to solve our box printing problem: ```python diff --git a/getting-help.md b/getting-help.md index 6080b67..c621433 100644 --- a/getting-help.md +++ b/getting-help.md @@ -5,7 +5,7 @@ places to ask for help in. ## IRC -IRC is the oldest chatting service I know, but as of 2017, it's still +IRC is the oldest chatting service I know, but as of 2018, it's still in use, and a great way to get help in Python. You don't need to register anywhere, just click one of the links below and you're good to go.