Skip to content

Commit bffe351

Browse files
BethanyGErikSchierboom
authored andcommitted
Basics Concept Exercise Reformat - A Re-implementation of PR 2534 (exercism#2745)
* Edited basics exercise and change inline links to refrence links. * Alphabetized in-doc links, edited down introduction.md and edited down links.json * More editing down of introduction.md
1 parent 5c97671 commit bffe351

File tree

3 files changed

+215
-106
lines changed

3 files changed

+215
-106
lines changed

concepts/basics/about.md

Lines changed: 83 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
1-
[Python](https://docs.python.org/3/) is a [dynamic and strongly](https://stackoverflow.com/questions/11328920/is-python-strongly-typed) typed [object-oriented](https://en.wikipedia.org/wiki/Object-oriented_programming) programming language. As of version 3.5, it employs both [duck typing](https://en.wikipedia.org/wiki/Duck_typing) and [gradual typing](https://en.wikipedia.org/wiki/Gradual_typing), via [type hints](https://docs.python.org/3/library/typing.html). It supports both imperative (_object-oriented, procedural_) and declarative (_functional, concurrent_) programming paradigms. But do not be fooled: while programming in other paradigms is fully _supported_, [everything in Python is an object](https://docs.python.org/3/reference/datamodel.html).
1+
## basics
22

3-
Python was created by Guido van Rossum and first released in 1991. The [Python Software Foundation](https://www.python.org/psf/) manages and directs resources for Python and CPython development and receives proposals for changes to the language from [members](https://www.python.org/psf/membership/) of the community via [Python Enhancement Proposals or PEPs](https://www.python.org/dev/peps/).
3+
[Python][python docs] is a [dynamic and strongly][dynamic typing in python] typed [object-oriented][object oriented programming] programming language. It employs both [duck typing][duck typing] and [gradual typing][gradual typing], via [type hints][type hints]. It supports multiple programming paradigms including both imperative (_object-oriented, procedural_) and declarative (_functional, concurrent_) flavors. But do not be fooled: while programming across paradigms is fully _supported_, [everything in Python is an object][everythings an object].
44

5-
Python puts a strong emphasis on code readability and (_similar to Haskell_) uses [significant indentation](https://docs.python.org/3/reference/lexical_analysis.html#indentation) to denote function, method, and class definitions. The [zen of Python (PEP 20)](https://www.python.org/dev/peps/pep-0020/) lays out additional inspiration and philosophy.
5+
Python was created by Guido van Rossum and first released in 1991. The [Python Software Foundation][psf] manages and directs resources for Python and CPython development and receives proposals for changes to the language from [members][psf membership] of the community via [Python Enhancement Proposals or PEPs][peps].
66

7-
Objects are [assigned](https://docs.python.org/3/reference/simple_stmts.html#assignment-statements) to [names](https://docs.python.org/3/reference/executionmodel.html#naming-and-binding) in Python via the `=` or _assignment operator_. [Variables](https://realpython.com/python-variables/) are written in [`snake_case`](https://en.wikipedia.org/wiki/Snake_case), and _constants_ usually in `SCREAMING_SNAKE_CASE`. A name (_variable or constant_) is not itself _typed_, and can be attached or re-attached to different objects over its lifetime. For extended naming conventions and advice, see [PEP 8](https://www.python.org/dev/peps/pep-0008/).
7+
Python puts a strong emphasis on code readability and (_similar to Haskell_) uses [significant indentation][significant indentation] to denote function, method, and class definitions. The [zen of Python (PEP 20)][the zen of python] lays out additional philosophy, as does the essay [What is Pythonic?][what is pythonic].
8+
9+
Complete documentation for the Python programming language can be found at [docs.python.org/3/][python docs]:
10+
11+
- [Python Tutorial][python tutorial]
12+
- [Python Library Reference][python library reference]
13+
- [Python Language Reference][python language reference]
14+
- [Python HOW TOs][python how tos]
15+
- [Python FAQs][python faqs]
16+
- [Python Glossary of Terms][python glossary of terms]
17+
18+
### Getting Started
19+
20+
Objects are [assigned][assignment statements] to [names][naming and binding] in Python via the `=` or _assignment operator_. [Variables][variables] are written in [`snake_case`][snake case], and _constants_ usually in `SCREAMING_SNAKE_CASE`. A name (_variable or constant_) is not itself _typed_, and can be attached or re-attached to different objects over its lifetime. For extended naming conventions and advice, see [PEP 8][pep8].
821

922
```python
1023
>>> my_first_variable = 1
1124
>>> my_first_variable = "Last one, I promise"
1225
>>> print(my_first_variable)
26+
1327
"Last one, I promise"
1428
```
1529

16-
Constants are usually defined on a [module](https://docs.python.org/3/tutorial/modules.html) or _global_ level, and although they _can_ be changed, they are _intended_ to be named only once. Their `SCREAMING_SNAKE_CASE` is a message to other developers that the assignment should not be altered:
30+
Constants are usually defined on a [module][module] or _global_ level, and although they _can_ be changed, they are _intended_ to be named only once. Their `SCREAMING_SNAKE_CASE` is a message to other developers that the assignment should not be altered:
1731

1832
```python
1933
# All caps signal that this is intended as a constant
@@ -24,36 +38,35 @@ MY_FIRST_CONSTANT = 16
2438
# Please don't do: MY_FIRST_CONSTANT = "Some other value"
2539
```
2640

27-
In Python, units of functionality are encapsulated in [functions](https://docs.python.org/3/reference/compound_stmts.html#function), which are themselves [objects](https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy) (_Its [turtles all the way down](https://en.wikipedia.org/wiki/Turtles_all_the_way_down)_).
28-
29-
Functions can be executed by themselves, passed as arguments to other functions, nested, or bound to a class. When functions are bound to a [class](https://docs.python.org/3/reference/datamodel.html#classes) name, they're referred to as [methods](https://docs.python.org/3/c-api/method.html#method-objects). Related functions and classes (_with their methods_) can be grouped together in the same file or [module](https://docs.python.org/3/reference/datamodel.html#modules), and imported in part or in whole for use in other programs.
41+
In Python, units of functionality are encapsulated in [_functions._][functions], which are themselves [objects][objects] (_Its [turtles all the way down][turtles all the way down]_). Functions can be executed by themselves, passed as arguments to other functions, nested, or bound to a class. When functions are bound to a [class][classes] name, they're referred to as [methods][method objects]. Related functions and classes (_with their methods_) can be grouped together in the same file or module, and imported in part or in whole for use in other programs.
3042

31-
The keyword `def` begins a [function definition](https://docs.python.org/3/tutorial/controlflow.html#defining-functions). It must be followed by the function name and a parenthesized list of zero or more formal [parameters](https://docs.python.org/3/glossary.html#term-parameter), which can be of several different varieties, and even [vary](https://docs.python.org/3/tutorial/controlflow.html#more-on-defining-functions) in length.
32-
33-
The `def` line is terminated with a colon. Statements for the _body_ of the function begin on the next line, and must be _indented in a block_. There is no strict indentation amount (_either space **OR** [tab] characters are acceptable_), but [indentation](https://docs.python.org/3/reference/lexical_analysis.html#indentation) must be _consistent for all indented statements_. Functions explicitly return a value or object via the [`return`](https://docs.python.org/3/reference/simple_stmts.html#return) keyword. Functions that do not have an explicit `return` expression will return [`None`](https://docs.python.org/3/library/constants.html):
43+
The keyword `def` begins a [function definition][function definition]. It must be followed by the function name and a parenthesized list of zero or more formal [parameters][parameters], which can be of several different varieties, and even [vary][more on functions] in length. The `def` line is terminated with a colon.
3444

3545
```python
3646
#function definition on first line.
3747
def add_two_numbers(number_one, number_two):
38-
return number_one + number_two #returns the sum of the numbers
48+
return number_one + number_two #returns the sum of the numbers, and is indented by 2 spaces.
3949

4050
>>> add_two_numbers(3, 4)
4151
7
4252

43-
#this function has no return keyword, and so will return None
44-
def multiply_two_numbers(number_one, number_two):
45-
result = number_one * number_two
46-
47-
>>> print(multiply_two_numbers(6, 8))
48-
None
53+
#the return statement line does not match the first line indent
54+
>>> def add_three_numbers_misformatted(number_one, number_two, number_three):
55+
... result = number_one + number_two + number_three #indented by 4 spaces
56+
... return result #this was only indented by 3 spaces
57+
File "<stdin>", line 3
58+
return result
59+
^
60+
IndentationError: unindent does not match any outer indentation level
4961
```
5062

51-
Functions are [called](https://docs.python.org/3/reference/expressions.html#calls) using their name followed by `()`. The number of arguments passed in the parentheses must match the number of parameters in the original function definition unless [default arguments](https://docs.python.org/3/tutorial/controlflow.html#default-argument-values) have been used:
63+
Statements for the _body_ of the function begin on the next line down from `def`, and must be _indented in a block_. There is no strict indentation amount (_either space **OR** [tab] characters are acceptable_), but [indentation][indentation] must be _consistent for all indented statements_. Functions explicitly return a value or object via the [`return`][return] keyword. Functions that do not have an explicit `return` expression will return [`None`][none].
64+
65+
Functions are [_called_][calls] using their name followed by `()`. The number of arguments passed in the parentheses must match the number of parameters in the original function definition unless [default arguments][default aruguments] have been used:
5266

5367
```python
5468
def number_to_the_power_of(number_one, number_two):
5569
'''Returns float or int.
56-
5770
Takes number_one and raises it to the power of number_two, returning the result.
5871
'''
5972

@@ -67,11 +80,9 @@ Traceback (most recent call last):
6780
File "<stdin>", line 1, in <module>
6881
TypeError: number_to_the_power_of() missing 1 required positional argument: 'number_two'
6982

70-
...
7183

7284
def number_to_the_power_of_default(number_one, number_two=2):
7385
'''Returns float or int.
74-
7586
Takes number_one and raises it to the power of number_two, returning the result.
7687
'''
7788

@@ -81,26 +92,27 @@ def number_to_the_power_of_default(number_one, number_two=2):
8192
16
8293
```
8394

84-
Methods bound to class names are invoked via _dot notation_ (`.`), as are functions, constants, or global names imported as part of a _module_.:
95+
Methods bound to class names are invoked via dot notation (.), as are functions, constants, or global names imported as part of a module.:
8596

8697
```python
98+
8799
import string
88100

89-
#this is a constant provided by the *string* module
101+
# this is a constant provided by the *string* module
90102
>>> print(string.ascii_lowercase)
91103
"abcdefghijklmnopqrstuvwxyz"
92104

93-
#this is a method call of the str *class*
105+
# this is a method call of the str *class*
94106
>>> start_text = "my silly sentence for examples."
95107
>>> str.upper(start_text)
96108
"MY SILLY SENTENCE FOR EXAMPLES."
97109

98-
#this is a method call of an *instance* of the str *class*
110+
# this is a method call of an *instance* of the str *class*
99111
>>> start_text.upper()
100112
"MY SILLY SENTENCE FOR EXAMPLES."
101113
```
102114

103-
[Comments](https://realpython.com/python-comments-guide/#python-commenting-basics) in Python start with a `#` that is not part of a string, and end at line termination. Unlike many other programming languages, Python does not support multi-line comment marks. Each line of a comment block must start with the `#` character. Comments are ignored by the interpreter:
115+
[Comments][comments] in Python start with a `#` that is not part of a string, and end at line termination. Unlike many other programming languages, Python does not support multi-line comment marks. Each line of a comment block must start with the `#` character. Comments are ignored by the interpreter:
104116

105117
```python
106118
#this is a single line comment
@@ -112,7 +124,7 @@ x = "foo" #this is an in-line comment
112124
#these should be used sparingly
113125
```
114126

115-
The first statement of a function body can optionally be a [docstring](https://docs.python.org/3/tutorial/controlflow.html#tut-docstrings), which concisely summarizes the function or object's purpose. These docstrings are read by automated documentation tools, and are returned by calling `__doc__` on the function, method, or class. They are recommended for programs of any size where documentation is needed:
127+
The first statement of a function body can optionally be a [_docstring_][docstring], which concisely summarizes the function or object's purpose. These docstrings are read by automated documentation tools, and are returned by calling **doc** on the function, method, or class. . They are recommended for programs of any size where documentation is needed:
116128

117129
```python
118130
#an example on a user-defined function
@@ -143,4 +155,46 @@ encoding defaults to sys.getdefaultencoding().
143155
errors defaults to 'strict'.
144156
```
145157

146-
Docstrings can also include [doctests](https://docs.python.org/3/library/doctest.html), which are interactive examples of how a method or function should work. Doctests can be read and run by PyTest, or by importing the `doctest` module.
158+
Docstrings can also include [doctests][doctests], which are interactive examples of how a method or funtion should work. Doctests can be read and run by PyTest, or by importing the `doctest` module.
159+
160+
[assignment statements]: https://docs.python.org/3/reference/simple_stmts.html#assignment-statements
161+
[calls]: https://docs.python.org/3/reference/expressions.html#calls
162+
[classes]: https://docs.python.org/3/reference/datamodel.html#classes
163+
[comments]: https://realpython.com/python-comments-guide/#python-commenting-basics
164+
[default arguments]: https://docs.python.org/3/tutorial/controlflow.html#default-argument-values
165+
[docstring]: https://docs.python.org/3/tutorial/controlflow.html#tut-docstrings
166+
[doctests]: https://docs.python.org/3/library/doctest.html
167+
[duck typing]: https://en.wikipedia.org/wiki/Duck_typing
168+
[dynamic typing in python]: https://stackoverflow.com/questions/11328920/is-python-strongly-typed
169+
[everythings an object]: https://docs.python.org/3/reference/datamodel.html
170+
[function definition]: https://docs.python.org/3/tutorial/controlflow.html#defining-functions
171+
[functions]: https://docs.python.org/3/reference/compound_stmts.html#function
172+
[gradual typing]: https://en.wikipedia.org/wiki/Gradual_typing
173+
[indentation]: https://docs.python.org/3/reference/lexical_analysis.html#indentation
174+
[method objects]: https://docs.python.org/3/c-api/method.html#method-objects
175+
[module]: https://docs.python.org/3/tutorial/modules.html
176+
[more on functions]: https://docs.python.org/3/tutorial/controlflow.html#more-on-defining-functions
177+
[naming and binding]: https://docs.python.org/3/reference/executionmodel.html#naming-and-binding
178+
[none]: https://docs.python.org/3/library/constants.html
179+
[object oriented programming]: https://en.wikipedia.org/wiki/Object-oriented_programming
180+
[objects]: https://docs.python.org/3/reference/datamodel.html#the-standard-type-hierarchy
181+
[parameters]: https://docs.python.org/3/glossary.html#term-parameter
182+
[pep8]: https://www.python.org/dev/peps/pep-0008/
183+
[peps]: https://www.python.org/dev/peps/
184+
[psf membership]: https://www.python.org/psf/membership/
185+
[psf]: https://www.python.org/psf/
186+
[python docs]: https://docs.python.org/3/
187+
[python faqs]: https://docs.python.org/3/faq/index.html
188+
[python glossary of terms]: https://docs.python.org/3/glossary.html
189+
[python how tos]: https://docs.python.org/3/howto/index.html
190+
[python language reference]: https://docs.python.org/3/reference/index.html
191+
[python library reference]: https://docs.python.org/3/library/index.html
192+
[python tutorial]: https://docs.python.org/3/tutorial/index.html
193+
[return]: https://docs.python.org/3/reference/simple_stmts.html#return
194+
[significant indentation]: https://docs.python.org/3/reference/lexical_analysis.html#indentation
195+
[snake case]: https://en.wikipedia.org/wiki/Snake_case
196+
[the zen of python]: https://www.python.org/dev/peps/pep-0020/
197+
[turtles all the way down]: https://en.wikipedia.org/wiki/Turtles_all_the_way_down
198+
[type hints]: https://docs.python.org/3/library/typing.html
199+
[variables]: https://realpython.com/python-variables/
200+
[what is pythonic]: https://blog.startifact.com/posts/older/what-is-pythonic.html

0 commit comments

Comments
 (0)