pyvec / pyvec/naucse.python.cz

Strings: Justify zero-based indexing

Open
#631 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

beginners-course content
Dominant language
No language data
Stars
335
Forks
119
Avg merge
3h 6m
Merged PRs (30d)
1

Description

As reported by @Kobzol in #628:

Maybe we should attempt to justify zero-based indexing without resorting to statements such as "it's black magic"? Pointer-based reasoning is too complex and also not really applicable to Python, but maybe we can find better justifications.

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:

Jak sis možná už všiml{{a}}, programátoři počítají od nuly.
...
Proč je tomu tak? Zjednodušeně řečeno je to z mnoha důvodů praktičtější.
Některé důvody jsou zatím moc komplikované a odkážeme se na ně později, ale prozatím si například můžeš všimnout, že:

<< intuitivní a jednoduchý příklad >>
<< např.: K indexování používáme v Pythonu celá čísla. Kladné indexy nám vrací prvky od začátku řetězce, záporné indexy prvky od konce řetězce, ale pokud bychom začali počítat od jedničky, jaký prvek by poté vrátil index 0? Bylo by nepraktické mít hodnotu indexu, která by nikdy nebyla validní >>

Počítání od nuly se používá ve většině programovacích jazyků, a i když ti prozatím může přijít zvláštní, časem si na něj určitě zvykneš. Můžeš si to představovat tak, že (kladný) index N udává počet prvků od začátku řetězce/pole, o které se musíš posunout, aby ses dostal(a) k žádanému prvku.

Later, for example in slicing/substrings (s[0:n]), we can refer to this with something like "Zde je příklad toho, proč je indexování od 0 přirozenější" and talk about open-closed intervals.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the course material that first introduces zero-based indexing and read the later slicing or substring sections referenced in the issue. Draft a beginner-appropriate justification with a concrete example and later cross-reference, then verify that the explanation is consistent with the surrounding lesson and clearly explains what learners should understand.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
content, documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.