Skip to content

Commit 83b43c3

Browse files
committed
stuffffs
1 parent c792fc0 commit 83b43c3

File tree

4 files changed

+122
-182
lines changed

4 files changed

+122
-182
lines changed

basics/getting-started.md

Lines changed: 37 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ That worked. How about numbers?
4747

4848
There we go, it echoes them back.
4949

50-
In some countries, decimal numbers are written with a comma, like `3,14`
51-
instead of `3.14`. Maybe Python knows that?
50+
In some countries, decimal numbers are written like `3,14` instead of
51+
`3.14`. Maybe Python knows that?
5252

5353
```python
5454
>>> 3,14
@@ -60,65 +60,70 @@ We didn't get an error... but `(3, 14)` is not at all what we expected!
6060
So from now on, let's use a dot with decimal numbers, because `3.14`
6161
worked just fine. Later we'll learn what `(3, 14)` is.
6262

63+
Python also supports simple math:
64+
65+
```python
66+
>>> 3 + 2
67+
5
68+
>>> 3 - 2
69+
1
70+
>>> 3 * 2
71+
6
72+
>>> 3 / 2
73+
1.5
74+
>>>
75+
```
76+
6377
## Comments
6478

65-
**Comments are text that does nothing.** They can be created by typing a
66-
`#` and then some text after it, and they are useful when our code would
67-
be hard to understand without them.
79+
**Comments are text that does nothing.** Everything after a `#` is ignored.
80+
Like this:
6881

6982
```python
7083
>>> 1 + 2 # can you guess what the result is?
7184
3
7285
>>>
7386
```
7487

75-
Again, I put a space after the `#` and multiple spaces before it just to
76-
make things easier to read.
88+
Comments are useful for explaining something to people reading the code.
7789

78-
If we write a comment on a line with no code on it, the prompt changes
79-
from `>>>` to `...`. To be honest, I have no idea why it does that and I
80-
think it would be better if it would just stay as `>>>`. The prompt goes
81-
back to `>>>` when we press Enter again.
90+
The interactive prompt does this if you enter a comment on a line with
91+
nothing else on it:
8292

8393
```python
8494
>>> # hello there
8595
...
8696
>>>
8797
```
8898

99+
I have no idea why this happens and I think it would be better if the
100+
prompt would just stay as `>>>`. Press Enter twice to get the prompt
101+
back to `>>>`.
102+
89103
## Strings
90104

91105
Strings are small pieces of text that we can use in our programs. We can
92-
create strings by simply writing some text in quotes.
106+
create strings like this:
93107

94108
```python
95109
>>> 'hello'
96110
'hello'
97111
>>> 'this is a test'
98112
'this is a test'
99-
>>>
100-
```
101-
102-
Strings can also be written with "double quotes" instead of 'single
103-
quotes'. This is useful when we need to put quotes inside the string.
104-
105-
```python
106-
>>> "hello there"
107-
'hello there'
108-
>>> "it's sunny"
109-
"it's sunny"
110-
>>>
113+
>>> 'string with a # in it'
114+
'string with a # in it'
115+
>>> 'test'
116+
'test'
117+
>>> "test"
118+
'test'
111119
```
112120

113-
It's also possible to add single quotes and double quotes into the same
114-
string, but most of the time we don't need to do that so I'm not going
115-
to talk about it now.
116-
117-
It doesn't matter which quotes you use when the string doesn't need to
118-
contain any quotes. If you think that one of the quote types looks nicer
119-
than the other or you find it faster to type, go ahead and use that.
121+
It doesn't matter if you use 'single quotes' or "double quotes". Python
122+
prefers single quotes when displaying strings to us, but it understands
123+
both quote styles. Double quotes are useful for strings that contain
124+
single quotes, like `"it's weird"`.
120125

121-
Strings can be joined together easily with `+` or repeated with `*`:
126+
You can also do this:
122127

123128
```python
124129
>>> "hello" + "world"
@@ -128,75 +133,6 @@ Strings can be joined together easily with `+` or repeated with `*`:
128133
>>>
129134
```
130135

131-
Note that a `#` inside a string doesn't create a comment.
132-
133-
```python
134-
>>> "strings can contain # characters"
135-
'strings can contain # characters'
136-
>>>
137-
```
138-
139-
## Using Python as a calculator
140-
141-
```diff
142-
---------- WARNING: This part contains boring math. Proceed with caution. ----------
143-
```
144-
145-
Let's type some math stuff into Python and see what it does.
146-
147-
```python
148-
>>> 17 + 3
149-
20
150-
>>> 17 - 3
151-
14
152-
>>> 17 * 3
153-
51
154-
>>> 17 / 3
155-
5.666666666666667
156-
>>>
157-
```
158-
159-
It's working, Python just calculates the result and echoes it back.
160-
161-
I added a space on both sides of `+`, `-`, `*` and `/`. Everything would
162-
work without those spaces too:
163-
164-
```python
165-
>>> 4 + 2 + 1
166-
7
167-
>>> 4+2+1
168-
7
169-
>>>
170-
```
171-
172-
However, I recommend always adding the spaces because they make the code
173-
easier to read.
174-
175-
Things are calculated in the same order as in math. The parentheses `(`
176-
and `)` also work the same way.
177-
178-
```python
179-
>>> 1 + 2 * 3 # 2 * 3 is calculated first
180-
7
181-
>>> (1 + 2) * 3 # 1 + 2 is calculated first
182-
9
183-
>>>
184-
```
185-
186-
You can also leave out spaces to show what's calculated first. Python
187-
ignores it, but our code will be easier to read for people.
188-
189-
```python
190-
>>> 1 + 2*3 # now it looks like 2*3 is calculated first
191-
7
192-
>>>
193-
```
194-
195-
Python also supports many other kinds of calculations, but most of the
196-
time you don't need them. Actually you don't need even these
197-
calculations most of the time, but these calculations are probably
198-
enough when you need to calculate something.
199-
200136
## Summary
201137

202138
[comment]: # (the first line in this summary is exactly same as in)

basics/installing-python.md

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ break them.
4646

4747
## Running Python
4848

49-
Next we'll learn to run Python on a PowerShell or terminal. There are
50-
several other ways to run Python, but if you learn this way now it's
51-
going to make things easier later.
49+
Next we'll learn to use the Python we just installed.
5250

5351
### Windows
5452

@@ -68,12 +66,70 @@ going to make things easier later.
6866

6967
Your terminal probably looks different than mine, it's OK.
7068

71-
Now you can type `exit()` and press Enter to get out of Python. Or you
72-
can just close the PowerShell or Terminal window.
69+
Go ahead and write `print("Hello World!")` after the `>>>`, and then
70+
press Enter, and Python will respond with a classic greeting :)
71+
72+
When you're done type `exit()` and press Enter to get out of Python, and
73+
then close the terminal or PowerShell window.
74+
75+
## The Editor
76+
77+
Python starts into a handy `>>>` prompt by default, and it's awesome for
78+
trying out how things work. But programmers spend most of their time
79+
writing **programs** into files instead of just writing little pieces of
80+
code on a prompt.
81+
82+
An **editor** lets you save code to files. There are many editors, and
83+
the choice of editor is a very personal thing. Each programmer has their
84+
own favorite editor that they tend to recommend to everyone. If you
85+
already know which editor you want to use, just [set it up](editor-setup.md)
86+
and [skip the rest of this chapter](#summary). Otherwise keep reading.
87+
88+
Your computer probably came with an editor, but it probably lacks lots
89+
of important features because it isn't meant to be used for programming
90+
and you need a better editor. For example, Windows comes with Notepad
91+
but it's lacking many important features that make writing Python code
92+
easier. Python also comes with its own editor called IDLE, but it also
93+
lacks a few features (even though it's better than Notepad).
94+
95+
I recommend [Porcupine](https://github.com/Akuli/porcupine/blob/master/README.md)
96+
because I made it and it's easy to use. **[Click here to install
97+
it.](https://github.com/Akuli/porcupine/wiki/Installing-and-Running-Porcupine)**
98+
99+
## Using the Editor
100+
101+
*__Note:__ This section assumes that you use Porcupine. You may need to
102+
do something differently if you use another editor.*
103+
104+
Open your editor and press *Ctrl+N* create a new file in it. Then save
105+
it with *Ctrl+S* and choose whatever folder you want. The file name can
106+
be anything you want, but **it must end with `.py`**. For example,
107+
`wat.py` is OK but `lolz` is not. This way your editor knows that you
108+
want to create a python file.
109+
110+
Now type this code into the editor:
111+
112+
```python
113+
print("Hello World")
114+
print("Testing... 1 2 3")
115+
print("Goodbye")
116+
```
117+
118+
You should see something like this:
119+
120+
![First program!](images/first-program.png)
121+
122+
Press *Ctrl+S* again to save the file (this time the editor remembers
123+
where it is and you don't need to choose a location and filename again).
124+
Then press *F5* to run the code. As you can see, it simply runs line by
125+
line, top to bottom.
73126

74127
## Summary
75128

76-
Now you should have Python installed, and you should be able run it.
129+
- Now you should have Python installed, and you should be able run its
130+
`>>>` prompt.
131+
- You should also have an editor that lets you write code to files and
132+
run the code.
77133

78134
***
79135

0 commit comments

Comments
 (0)