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
Copy file name to clipboardExpand all lines: try_python/README.md
+27-27Lines changed: 27 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,14 +6,14 @@ Let's write some code!
6
6
7
7
To start tinkering with Python, we need to open up a *prompt* on your computer. On Mac OS X you can do this by launching `Terminal` application (It's in Applications → Utilities). On Windows you need to go to Start menu → All Programs → Accessories → Command Prompt. On Linux, it's probably under Applications → Accessories → Terminal.
8
8
9
-
Black window should pop up on your screen. This window is waiting for a command from you. We want to open up a Python console, so type in `python` and hit Enter.
9
+
A window should pop up on your screen. This window is a prompt, waiting for commands from you. We want to open up a Python console, so type in `python` and hit Enter.
10
10
11
11
(workshops) ~$ python
12
12
Python 3.4.0 (...)
13
13
Type "copyright", "credits" or "license" for more information.
14
14
>>>
15
15
16
-
Earlier we were working in the operating system’s command line and we could give commands. The prompt was `~$`. After running the python command, prompt changed to `>>>`. For us that means that for now we may use commands only in Python language. You don't have to type in `>>>` - Python will do that for you.
16
+
After running the python command, prompt changed to `>>>`. For us it means that for now we may use commands only in Python language. You don't have to type in `>>>` - Python will do that for you.
17
17
18
18
## Your first Python command!
19
19
@@ -22,14 +22,14 @@ Let's start with something really simple. For example, try typing some math, lik
22
22
>>> 2 + 3
23
23
5
24
24
25
-
Nice! See how the answer popped out? Python knows some math. You could try other commands like:
25
+
Nice! See how the answer popped out? Python knows math! You could try other commands like:
26
26
-`4 * 5`
27
27
-`5 - 1`
28
28
-`40 / 2`
29
29
30
30
Have fun with this for a little while and then get back here :)
31
31
32
-
As you can see, Python is a great calculator. If you're wonder what alse you can do...
32
+
As you can see, Python is a great calculator. If you're wonder what else you can do...
33
33
34
34
## Strings
35
35
@@ -38,7 +38,7 @@ Maybe your name? Type your first name in quotes like this:
38
38
>>> "Ola"
39
39
'Ola'
40
40
41
-
You now created your first string! It's a set of characters that can be processed by a computer. The string must always begin and end with the same character. This may be an apostrophe (`'`) or double quotes (`"`). It has no effect on the value of the string - double quotes or apostrophes are not a part of string, they only indicate that it is a string.
41
+
You now created your first string! It's a set of characters that can be processed by a computer. The string must always begin and end with the same character. This may be an apostrophe (`'`) or double quotes (`"`) - they tell Python that it is a string.
42
42
43
43
Strings can be added. Try this:
44
44
@@ -62,7 +62,7 @@ If you want to get a number of letters in your name, there is a method for that
62
62
>>> len("Ola")
63
63
3
64
64
65
-
Wonder why sometimes you call methods by adding `.` at the end of the string (like `"Ola".upper()`) and sometimes you first call a method and add string in parentheses? Well, in some cases, methods belong to objects, like `upper` that can only be performed on Strings. But sometimes, methods don't belong to anything specific and can be used on different types of objects, just like `len`. That's why we're giving `"Ola"` as a parameter to `len` method.
65
+
Wonder why sometimes you call methods by adding `.` at the end of the string (like `"Ola".upper()`) and sometimes you first call a method and place string in parentheses? Well, in some cases, methods belong to objects, like `upper` that can only be performed on Strings. But sometimes, methods don't belong to anything specific and can be used on different types of objects, just like `len`. That's why we're giving `"Ola"` as a parameter to `len` method.
66
66
67
67
### Summary
68
68
@@ -76,41 +76,41 @@ That's the basic of every programming language you learn. Ready for something ha
76
76
77
77
## Errors
78
78
79
-
Let's try something. Can we know the lenght of a number, the same way we learn the lenght of our name? Try typing `len(304023)` and hit Enter:
79
+
Let's try something. Can we know the length of a number, the same way we learn about the length of our name? Try typing `len(304023)` and hit Enter:
80
80
81
81
>>> len(304023)
82
82
Traceback (most recent call last):
83
83
File "<stdin>", line 1, in <module>
84
84
TypeError: object of type 'int' has no len()
85
85
86
-
We got our first error! It says that objects of type "int" (integers, whole numbers) doesn't have a lenght. Well.. so what can we do know? Maybe we can write our number as string? Strings have lenght, right?
86
+
We got our first error! It says that objects of type "int" (integers, whole numbers) doesn't have a length. So what can we do know? Maybe we can write our number as string? Strings have length, right?
87
87
88
88
>>> len(str(304023))
89
89
6
90
90
91
-
It worked! We used `str` method inside of `len` method. `str` is converting everything to Strings.
91
+
It worked! We used `str` method inside of `len` method. `str` is converting everything to strings.
92
92
93
93
-`str` method convert things into __strings__
94
94
-`int` method convert things into __integers__
95
95
96
-
As long as we can convert numbers into text, we can't convert text into numbers.
96
+
> Important: we can convert numbers into text, but we can't convert text into numbers.
97
97
98
98
## Variables
99
99
100
-
There is a concept in programming: variable. This is nothing more than a name for something so you can use the name rather than the something as you code. Programmers use these variable names to make their code more readable and so they won't forget what something is.
100
+
There is a concept in programming called variables. A variable is nothing more than a name for something so you can use it easier. Programmers use these variables to store data, make their code more readable and to not forget what something is.
101
101
102
102
Let's say we want to create a new variable called `name`:
103
103
104
104
>>> name = "Ola"
105
105
106
106
You see? It's easy! Simply: name equals Ola.
107
107
108
-
As you've noticed, your program didn't return anything as it did before. How do we now that the variable actually is there? Simply enter `name` and hit Enter:
108
+
As you've noticed, your program didn't return anything like it did before. How do we now that the variable actually is there? Simply enter `name` and hit Enter:
109
109
110
110
>>> name
111
111
'Ola'
112
112
113
-
Yikes! Your first variable :) You can always change what it means:
113
+
Yikes! Your first variable :) You can always change what it is:
114
114
115
115
>>> name = "Sonja"
116
116
>>> name
@@ -139,20 +139,20 @@ Go ahead and create a list:
139
139
>>> []
140
140
[]
141
141
142
-
Yes, it's empty. Not very useful, right? Let's create a list of lottery numbers. We don't want to repear ourselves all the time, so we will put it in a variable, too:
142
+
Yes, it's empty. Not very useful, right? Let's create a list of lottery numbers. We don't want to repeat ourselves all the time, so we will put it in a variable, too:
143
143
144
144
>>> lottery = [3, 42, 12, 19, 30, 59]
145
145
146
-
All right, we have a list! What can we do with it? Let's see how many lottery numbers there is in a list. Do you have an idea which method you should use for that? You've know this already!
146
+
All right, we have a list! What can we do with it? Let's see how many lottery numbers there is in a list. Do you have an idea which method you should use for that? You know this already!
147
147
148
148
>>> len(lottery)
149
149
6
150
150
151
-
Yes! `len` can give you a number of objects in a list. Handy, right? Let's sort this list now.
151
+
Yes! `len` can give you a number of objects in a list. Handy, right? Maybe we will sort it now:
152
152
153
153
>>> lottery.sort()
154
154
155
-
This doesn't return anything... because we didn't print it! Let's try this:
155
+
This doesn't return anything... because we didn't print it! Try this:
156
156
157
157
>>> print(lottery)
158
158
[3, 12, 19, 30, 42, 59]
@@ -190,11 +190,11 @@ Awesome! You know a lot about programming now. In the last part you learned abou
190
190
-__variables__ - names for objects that allow to code more easily and make your code more readable
191
191
-__lists__ - list of objects stored in particular order.
192
192
193
-
Exicted for the next part? :)
193
+
Excited for the next part? :)
194
194
195
195
## Compare things
196
196
197
-
The big part of programming includes comparing things together. What's the easiest thing to compare? Numbers, of course. Let's see how it works:
197
+
The big part of programming includes comparing things. What's the easiest thing to compare? Numbers, of course. Let's see how it works:
198
198
199
199
>>> 5 > 2
200
200
True
@@ -207,9 +207,9 @@ The big part of programming includes comparing things together. What's the easie
207
207
208
208
We gave Python some numbers to compare. As you can see, Python can compare not only numbers, but it can also compare method results. Nice, huh?
209
209
210
-
Do you wonder why we put two `==` next to each other to compare if numbers are equal? We use single `=` for asserting value to variables, so Python would think that we're trying to do that. You always, __always__ need to put two `==` if you want to check if things are equal to each other.
210
+
Do you wonder why we put two `==` next to each other to compare if numbers are equal? We use single `=` for assigning value to variables, so Python would think that we're trying to do that. You always, __always__ need to put two `==` if you want to check if things are equal to each other.
211
211
212
-
Let's give Python two more tasks:
212
+
Give Python two more tasks:
213
213
214
214
>>> 6 >= 12 / 2
215
215
True
@@ -223,7 +223,7 @@ Let's give Python two more tasks:
223
223
- x `<=` y - x is smaller or equal to y
224
224
- x `>=` y - x is greater or equal to y
225
225
226
-
Awesome! Wanna do one more? Let's try this:
226
+
Awesome! Wanna do one more? Try this:
227
227
228
228
>>> 6 > 2 and 2 < 3
229
229
True
@@ -234,12 +234,12 @@ Awesome! Wanna do one more? Let's try this:
234
234
235
235
You can give Python as many numbers to compare as you want, and he will give you an answer! Pretty smart, right?
236
236
237
-
-__and__ - if you use `and` operator, both of the comparisions have to be True in order for the whole thing to be True
238
-
-__or__ - if you use `or` operator, only one of the comparisions has to be True in order for the whole thing to be True
237
+
-__and__ - if you use `and` operator, both of the comparisons have to be True in order for the whole thing to be True
238
+
-__or__ - if you use `or` operator, only one of the comparisons has to be True in order for the whole thing to be True
239
239
240
240
## Boolean
241
241
242
-
Accidantely, you just learned about a new type of object in Python. It's __boolean__ -- probably the easiest type there is.
242
+
Accidently, you just learned about a new type of object in Python. It's __boolean__ -- probably the easiest type there is.
243
243
244
244
Boolean can be only two things:
245
245
- True
@@ -270,7 +270,7 @@ Congrats! You can know move on to the essence of programming:
270
270
271
271
## If...elif...else
272
272
273
-
Lots of things in code should only be exectured when given conditions are met. That's why Python has something called __if statements__.
273
+
Lots of things in code should only be executed when given conditions are met. That's why Python has something called __if statements__.
274
274
275
275
Try this:
276
276
@@ -388,7 +388,7 @@ As you can see, we needed to put two tabs before `print` function, because `if`
388
388
>>> hi("Anja")
389
389
Hi anonymous!
390
390
391
-
Awesome, right? This way you don't have to repeat yourself everytime you want to change the name. And that's exactly why we need functions - you never want to repeat your code!
391
+
Awesome, right? This way you don't have to repeat yourself every time you want to change the name. And that's exactly why we need functions - you never want to repeat your code!
392
392
393
393
Let's do something smarter -- there is more names than two, and writing a condition for each would be hard, right?
0 commit comments