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: _posts/2020-11-26-lecture-notes-1.md
+20-20Lines changed: 20 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,7 +68,7 @@ Although please note that the print function is run by default in your shell. Th
68
68
Hello World!
69
69
```
70
70
71
-
##What objects?
71
+
# What objects?
72
72
73
73
I like to make this course more focused on the object-oriented part of python because although it may sound hard now, this will ease a lot of stuff. You might have found it odd that I've said python prints *objects* to the screen in the 'Hello World!' example. But it is in fact true. Every single 'thing' in python is an object. That `print()` function? Object. That `\n` character? Object. Hello world? Object. Now to avoid confusion and more so to make this language actually work, we need some objects to be different than others and this brings us to **object types**.
74
74
@@ -160,7 +160,7 @@ It isn't so
160
160
It isn't so
161
161
```
162
162
163
-
### Type conversions
163
+
## Type conversions
164
164
165
165
The last thing you should know about types is that you can convert them to each other. You can use the commands `int()`, `str()`, `list()`, `set()`for example, to do this. If we want to see it in action:
166
166
@@ -213,11 +213,11 @@ Here's a table of some data types and examples:
All these brings us to operators. Yes, I know, it's not as exiting to learn about data types and these basic stuff, but it'll be over soon. Operators are just like in math. They operate. I don't think high level explanations are very memorable so let's see some operators. Operators are *type-specific*, meaning that either they don't work for different types or that they work differently for different types. Don't try to memorize these. Try writing code that uses these operators. That'll make them stick more easily.
219
219
220
-
### Integer and float operators
220
+
## Integer and float operators
221
221
222
222
Addition
223
223
@@ -274,7 +274,7 @@ Raise to the power
274
274
275
275
**Note:** The same "order of operations" rules apply here too.
276
276
277
-
### String operators
277
+
## String operators
278
278
279
279
Appension or glueing strings together
280
280
@@ -290,7 +290,7 @@ Repetition
290
290
'ikbalikbalikbal'
291
291
```
292
292
293
-
### List operators
293
+
## List operators
294
294
295
295
List comprehension is a wide subject and there are lots you can do with lists. They are probably the most important and useful typeif we don't count booleans. But I'm not going to be focusing too much on that for this section since it won't be memorable. We'll have a section going in depth with lists soon. Some basic operations you should keep in mind are
296
296
@@ -321,7 +321,7 @@ Indexing
321
321
3
322
322
```
323
323
324
-
### Assignment operators
324
+
## Assignment operators
325
325
326
326
`=` You know this one.
327
327
@@ -338,7 +338,7 @@ Indexing
338
338
339
339
`*=`and`-=` You should be able to guess.
340
340
341
-
### Membership operators
341
+
## Membership operators
342
342
343
343
`in`
344
344
@@ -347,7 +347,7 @@ Indexing
347
347
True
348
348
```
349
349
350
-
### Identity operators
350
+
## Identity operators
351
351
352
352
`is`
353
353
@@ -357,7 +357,7 @@ True
357
357
True
358
358
```
359
359
360
-
### Comparison operators
360
+
## Comparison operators
361
361
362
362
`==`. Same with`is`. It checks whether objects on the ends are the same.
363
363
@@ -393,11 +393,11 @@ True
393
393
False
394
394
```
395
395
396
-
## Expressions
396
+
# Expressions
397
397
398
398
To be honest, all we were doing in the last section was checking the values of expressions. When you use objects with operators, you get expressions. For example `a = 5`is an expression just like `a is5`. Some of these expressions are logical arguments. You may have noticed that in a big part of the operators we just saw, the shell returned either TrueorFalse. These expressions which returnTrueorFalse are called logical statements just like in math. This brings us to **branching**.
399
399
400
-
## Branching
400
+
# Branching
401
401
402
402
Branching despite it's impressive name only means checking for a condition and running (or not running) code based on that condition. The basic statements for branching is `if`, `elif` and `else`. Remember the comparison operators? This is where we'll use them.
403
403
@@ -443,7 +443,7 @@ It is also possible to run this from the terminal on Linux and from `cmd` on Win
443
443
444
444
Enough Sublime Text, let's get back to how branching works.
445
445
446
-
### What happened?
446
+
## What happened?
447
447
448
448
1. The interpreter, when parsing the file comes to the if statement and stops.
449
449
2. The interpreter checks whether what comes after it isTrue. So in this case, the interpreter checks whether `True`isTrue.
@@ -510,7 +510,7 @@ Ikbal is ok.
510
510
[Finished in0.0s]
511
511
```
512
512
513
-
### What happened?
513
+
## What happened?
514
514
515
515
1. The interpreter checked the first if statement. It was `False` because `ikbal`!=`'pretty'`.
516
516
2. The interpreter checked the `elif` statement and it was `True` because `ikbal`!=`'ok'`.
@@ -522,7 +522,7 @@ So from this we can deduce:
522
522
523
523
Let's test our deduction. We'll set`ikbal` to be `'ok'`. Before running try to guess what'll happen on your own. It's always a good exercise to guess before you run your code so you may have a clue where you go wrong.
524
524
525
-
### Our guess
525
+
## Our guess
526
526
527
527
1. The interpreter will check `if``ikbal`==`'pretty'`and it will return`False` because it isn't.
528
528
2. The interpreter will check `elif``ikbal`!=`'ok'`and it will also return`False` because `ikbal`**is**`'ok'`and the statement returns `True` only when `ikbal`**isn't** `'ok'`.
@@ -550,7 +550,7 @@ So our guess was correct.
550
550
551
551
The last thing about branching that you need to know is**nested branching**. As it's name it's about *nesting* different branches.
552
552
553
-
### Nested branching
553
+
## Nested branching
554
554
555
555
Open a new fileand name it whatever you want (It should end with`.py`). This one is so simple that you don't even need an example for it but here goes:
556
556
@@ -570,7 +570,7 @@ This number is divisible by 1
570
570
[Finished in0.0s]
571
571
```
572
572
573
-
#### What happened?
573
+
### What happened?
574
574
575
575
1. The interpreter checked `if` the remainder from dividing `num` by 1 was 0. (So it checked whether `num` was divisible by 1) And 5**is** divisible by 1 so it ran the indented code.
576
576
2. It ran the `print()` function
@@ -580,7 +580,7 @@ Note that if the first `if` statement didn't run, the interpreter **wouldn't che
580
580
581
581
This brings us to the end of branching and to the last subject I want to talk about in this lesson.
582
582
583
-
## Functions
583
+
# Functions
584
584
585
585
You already saw one of these: the `print()`*function*. You'll come across more and more functions as you delve deeper. Don't make an effort to memorize them all at once, they won't stick. For this reason, this section doesn't focus on different functions you can use for different things but rather how to make your own functions.
586
586
@@ -701,9 +701,9 @@ Example:
701
701
three thirty pm
702
702
```
703
703
704
-
## Solutions
704
+
# Solutions
705
705
706
-
## Fixing Sublime for Linux
706
+
# Fixing Sublime for Linux
707
707
708
708
1. Go into `Tools > Build System > New Build System...`
0 commit comments