-
Notifications
You must be signed in to change notification settings - Fork 119
Rework lessons on strings #628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
In in-person courses, I tended to explain strings in more depth than what the materials provided. There's enough depth in quoting and characters (esp. special characters) to make it a separate lesson; same goes for the new concepts of indexing/slicing and methods. This splits the matrial into: - String literals (how to write strings; what is a character) - String indexing and slicing - String methods - F-strings (split out earlier) String comparisons might come later.
|
It looks good to me! One thing that I think could be improved, but it's not a big deal: There are multiple reasons why 0-based indexing is useful (open-closed intervals, multi-dimensional indexing, arrays represented with pointers to their first element, using modulo to calculate indices etc.). Some of them are too difficult for this part of the course, but maybe we can pick some examples that they can understand? Or if we can't find any, say that we will show some examples later and add specific references to zero-based indexing later. For example: Later, for example in slicing/substrings ( |
|
Thanks! I opened #631 with this idea. I would like to have this PR merged if it is an improvement, not if it is perfect. The PR doesn't change the explanation of zero-based indexing, so IMO this review is not a place to improve it. |
|
You're right, it's a separate discussion. |
| Zkus si, jestli zvládneš předpovědět výsledek těchto výrazů: | ||
|
|
||
| ```plain | ||
| [0] [1] [2] [3] [4] [5] [6] [7] | ||
| [-8][-7][-6][-5][-4][-3][-2][-1] | ||
| ╭───┬───┬───┬───┬───┬───┬───┬───╮ | ||
| │ Č │ o │ k │ o │ l │ á │ d │ a │ | ||
| ╰───┴───┴───┴───┴───┴───┴───┴───╯ | ||
| ```pycon | ||
| >>> print(".\".") | ||
| >>> len(".\".") | ||
| >>> ".\"." | ||
| ``` | ||
| {% endfilter %} | ||
|
|
||
| Řetězce umí i jiné triky. | ||
| Třeba můžeš zjistit, jak je řetězec dlouhý | ||
| nebo jestli v sobě obsahuje daný menší řetězec. | ||
|
|
||
| <table class="table"> | ||
| <tr> | ||
| <th>Zápis</th> | ||
| <th>Popis</th> | ||
| <th>Příklad</th> | ||
| </tr> | ||
| <tr> | ||
| <td><code>len(r)</code></td> | ||
| <td>Délka řetězce</td> | ||
| <td><code>len('čokoláda')</code></td> | ||
| </tr> | ||
| <tr> | ||
| <td><code>x in r</code></td> | ||
| <td>True pokud je řetězec <code>x</code> obsažen v <code>r</code></td> | ||
| <td><code>'oko' in 'čokoláda'</code></td> | ||
| </tr> | ||
| <tr> | ||
| <td><code>x not in r</code></td> | ||
| <td>Opak <code>x in r</code></td> | ||
| <td><code>'dub' not in 'čokoláda</code></td> | ||
| </tr> | ||
| </table> | ||
|
|
||
| Řetězce vždy berou v potaz velikost písmen, | ||
| takže např. `'ČOKO' in 'čokoláda'` je `False`. | ||
| Kdybys chtěl{{a}} porovnávat bez ohledu na velikost písmen, | ||
| musel{{a}} bys oba řetězce převést třeba na malá písmena | ||
| a pak je porovnat. | ||
|
|
||
| A jak se převádí na malá písmena? | ||
| K tomu budeme potřebovat další novou vlastnost Pythonu: metody. | ||
|
|
||
| ## Metody | ||
|
|
||
| *Metoda* (angl. *method*) je jako funkce – něco, co se dá zavolat. | ||
| Na rozdíl od funkce je svázaná s nějakým *objektem* (hodnotou). | ||
| Volá se tak, že se za objekt napíše tečka, | ||
| za ní jméno metody a za to celé se, jako u funkcí, připojí závorky | ||
| s případnými argumenty. | ||
|
|
||
| Řetězcové metody `upper()` a `lower()` | ||
| převádí text na velká, respektive malá písmena. | ||
|
|
||
| ```python | ||
| retezec = 'Ahoj' | ||
| print(retezec.upper()) | ||
| print(retezec.lower()) | ||
| print(retezec) | ||
| {% filter solution %} | ||
| ```pycon | ||
| >>> print(".\".") | ||
| .". | ||
| >>> len(".\".") | ||
| 3 | ||
| >>> ".\"." | ||
| '.".' | ||
| ``` | ||
| {% endfilter %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be an interesting part for experimenting, but IMHO should be all hidden by default and the box with this part would display when clicked on: Zkus si, jestli zvládneš předpovědět výsledek těchto výrazů
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should be hidden. People struggle with the fact that \" denotes a single character. The teacher could show these as an example, or skip this and use some other way to explain it, but IMO it is necessary to show the fact again, from a different angle.
| ```pycon | ||
| >>> print("a\tb") # Výpis "pro lidi" | ||
| a b | ||
| >>> "a\tb" # Výpis "pro programátory" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Výpis "pro programátor(k)y" ... I suggest fixing of all occurrences (I mean those which are part of this PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, that would be a suggestion for all the texts on naucse.
I don't see (k) used anywhere else yet. Generally I try to address the user with {{a}} (hoping that in the future, the page can adjust for logged-in users), but in cases like these use the Czech default.
| a b | ||
| >>> "a\tb" # Výpis "pro programátory" | ||
| 'a\tb' | ||
| >>> len("a\tb") # Počet znaků v řetězci |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is even more self-explaining of how len() considers the chars (includes not only explanation for "\" but also for "\t" as a whole, when it comes to pritning) than the experimenting section above, so this should be enough. The course teacher can use this example here to quickly/easily explain the behaviour...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you're suggesting here.
| standardu Unicode. | ||
| Stačí přesné jméno nebo číslo znát (nebo třeba dohledat na internetu). | ||
| V následujících řetězcích jsou takové znaky pro přehlednost mezi dvěma | ||
| pomlčkami `-`. Délka každého řetězce je tedy celkem 3: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here again it's well-explained.
|
I have just some small comments in the code. One major comment for a separate issue/PR, when the materials grow over time, some parts should be hidden and marked somehow (e.g. ℹ️ or |
We already have info and warning boxes, except they're not hidden by default. Also, the materials should be usable when printed out (for both teachers and students). Hidden boxes make this more complicated. Of course, this can be solved (and I hope it has been solved for the solutions). |
Co-authored-by: Karolina <33810531+befeleme@users.noreply.github.com>
fivaldi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a commit msg typo, but other than that looks good to me.
Thanks also for commenting on reviews.
There should be subsequent issues opened aiming on re-structuring of the content on major materials additions which make it difficult to choose the most important stuff for live lessons, as the materials keep growing.
Stats with this PR: +1,006 −266
OK, feel free to merge to move things forward, but let's keep in mind how it's gonna affect course teachers sooner or later. They need to pay more attention on what's really the most important and choose those parts.
Thank you!
|
Thanks for the review!
The best way to do this to teach a course, and send PRs or report back what you thought was good to leave out! |
|
I like it! |
In in-person courses, I tended to explain strings in more depth than what the materials provided.
There's enough depth in quoting and characters (esp. special characters) to make it a separate lesson; same goes for the new concepts of indexing/slicing and methods.
This splits the material into:
String comparisons might come later :)
Please review the changes as a whole, don't look at individual commits. But, to make cherry-picking easier, don't squash when merging.