You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Basics Concept Exercise Reformat - A Re-implementation of PR 2534
* 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
Copy file name to clipboardExpand all lines: concepts/basics/about.md
+83-29Lines changed: 83 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff 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
2
2
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].
4
4
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].
6
6
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]:
-[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].
8
21
9
22
```python
10
23
>>> my_first_variable =1
11
24
>>> my_first_variable ="Last one, I promise"
12
25
>>>print(my_first_variable)
26
+
13
27
"Last one, I promise"
14
28
```
15
29
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:
17
31
18
32
```python
19
33
# All caps signal that this is intended as a constant
@@ -24,36 +38,35 @@ MY_FIRST_CONSTANT = 16
24
38
# Please don't do: MY_FIRST_CONSTANT = "Some other value"
25
39
```
26
40
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.
30
42
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.
34
44
35
45
```python
36
46
#function definition on first line.
37
47
defadd_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.
39
49
40
50
>>> add_two_numbers(3, 4)
41
51
7
42
52
43
-
#this function has no return keyword, and so will return None
44
-
defmultiply_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
... 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
49
61
```
50
62
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:
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.:
85
96
86
97
```python
98
+
87
99
import string
88
100
89
-
#this is a constant provided by the *string* module
101
+
#this is a constant provided by the *string* module
90
102
>>>print(string.ascii_lowercase)
91
103
"abcdefghijklmnopqrstuvwxyz"
92
104
93
-
#this is a method call of the str *class*
105
+
#this is a method call of the str *class*
94
106
>>> start_text ="my silly sentence for examples."
95
107
>>>str.upper(start_text)
96
108
"MY SILLY SENTENCE FOR EXAMPLES."
97
109
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*
99
111
>>> start_text.upper()
100
112
"MY SILLY SENTENCE FOR EXAMPLES."
101
113
```
102
114
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:
104
116
105
117
```python
106
118
#this is a single line comment
@@ -112,7 +124,7 @@ x = "foo" #this is an in-line comment
112
124
#these should be used sparingly
113
125
```
114
126
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:
116
128
117
129
```python
118
130
#an example on a user-defined function
@@ -143,4 +155,46 @@ encoding defaults to sys.getdefaultencoding().
143
155
errors defaults to 'strict'.
144
156
```
145
157
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.
0 commit comments