-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
621 lines (550 loc) · 21 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<title>Python Crash Course book</title>
<link rel="stylesheet" href="main-style.css">
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;0,900;1,200;1,300;1,400;1,500;1,600;1,700;1,900&display=swap" rel="stylesheet">
</head>
<body><section class="body neooutside">
<h1>Chapter 1</h1>
content
<hr class="lvl1">
<h1>Chapter 2</h1>
<section class="term">Syntax Hilighting</section>
<h2>Variables</h2>
<section>
Variable Naming
<ul>
<li><strong>contain</strong> : A-Z a-z numbers _ </li>
<li><strong>start</strong> : A-Z a-z _ </li>
<li><strong>not be </strong> : specific python names (print,function,...) </li>
</ul>
</section>
<p>traceback</p>
<h2>Strings</h2>
<section>
only one kind of <span class="blue">'</span> or <span class="red">"</span> as wrapper <br>
<span class="blue">'</span> example <span class="red"> " </span> number1 <span class="red"> " </span> <span class="blue"> ' </span> <br>
<span class="red">"</span> example <span class="blue"> ' </span> number1 <span class="blue"> ' </span> <span class="red"> " </span> <br>
</section>
<p>
<h3>Changing Case in a String with Methods </h3>
<p>
<span class="neoinside inline-block"><var class="var_object">string</var>.title( )</span> : "ada lovelace" => "Ada Lovlace" <br>
<span>For example, you might want your program to recognize the input values Ada, ADA, and ada as the same name, and display all of them as Ada</span>
</p>
<p>
<span class="neoinside inline-block"><var class="var_object">string</var>.upper( )</span> : "ada lovelace" => "ADA LOVLACE" <br>
<span class="neoinside inline-block"><var class="var_object">string</var>.lower( )</span> : "Ada Lovelace" => "ada lovlace" <br>
<span>The lower() method is particularly useful for storing data. Many times you won’t want to trust the capitalization that your users provide, so you’ll convert strings to lowercase before storing them. Then when you want to display the information, you’ll use the case that makes the most sense for each string.</span>
</p>
</p>
<p>
<h3>Using Variables in Strings </h3>
<section><section class="term">f string</section>format string (f is for format)</section>
<section>full_name = <span class="blue">f</span>"<span class="red">{</span>first_name<span class="red">}</span> <span class="red">{</span>last_name<span class="red">}</span>"</section>
<section>
Example :
<code>
first_name = "ada"
last_name = "lovelace"
full_name = f"{first_name} {last_name}"
print(full_name)
</code>
</section>
<section>
Example of other kind :
<code>
full_name = "{} {}".format(first_name, last_name)
</code>
</section>
</p>
<h3>Adding Whitespace to Strings with Tabs or Newlines</h3>
<section>
<strong>\t</strong> is for tab <br><br>
Example :
<samp>
<span class="python_prompt">>>></span>print("Python")
Python
<span class="python_prompt">>>></span>print("\tPython")
Python
</samp>
</section>
<section>
<strong>\n</strong> is for new line <br><br>
Example :
<samp>
<span class="python_prompt">>>></span>print("Languages:\nPython\nC\nJavaScript")
Languages:
Python
C
JavaScript
</samp>
</section>
<h3>Stripping Whitespace </h3>
<section>
<samp>
>>> favorite_language = ' python '
>>> favorite_language.rstrip()
' python'
>>> favorite_language.lstrip()
'python '
favorite_language.strip()
'python'
</samp>
</section>
<h3>Avoiding Syntax Errors with Strings</h3>
<section class="term">syntax error</section>
<a href="(2-3_2-6)_Chapter1_Strings_try_it_yourself_page25.py">Try It Your Self Excersise File Page 25</a> <br><br>
Try It Your Self Note :
<samp>
>>> name = "\t python \n"
>>> print(name)
python
>>> print( name.lstrip() )
python
>>> print( name.rstrip() )
python
>>> print( name.strip() )
python
</samp>
<h2>Numbers</h2>
<h3>integer</h3>
<section>
Note : the answer of / operator is always a <strong>float</strong> number
<samp>
>>> 2 + 3
5
>>> 3 - 2
1
>>> 2 * 3
6
>>> 3 / 2
1.5
>>> 3 ** 2
9
</samp>
</section>
<h3>floats</h3>
<section>
Note : <section class="term">floating point</section>
<samp>
>>> 0.1 + 0.1
0.2
>>> 0.2 + 0.2
0.4
>>> 2 * 0.1
0.2
>>> 2 * 0.2
0.4
>>> 0.2 + 0.1
0.30000000000000004
>>> 3 * 0.1
0.30000000000000004
</samp>
</section>
<h3>integers and floats</h3>
<section>
Note : Python defaults to a float in any operation that uses a float, even if the output is a whole number.
<samp>
>>> 1 + 2.0
3.0
>>> 2 * 3.0
6.0
>>> 3.0 ** 2
9.0
</samp>
</section>
<h3>underscores in numbers </h3>
<section>
<strong>universe_age = 14_000_000_000</strong> is same as <strong>universe_age = 14000000000</strong> for python interpretor
<section>python omit <strong>_</strong> in numbers</section>
</section>
<h3>multiple assignments</h3>
<section>
<samp>
>>> x,y,z = 0,1.1,'example'
</samp>
</section>
<h3>constant</h3>
<section>
<code>
MAX_CONNECTIONS = 5000
</code>
Note : When you want to treat a variable as a constant in your code, make the name of the variable all capital letters.
</section>
<a href="(2-8_2-9)_Chapter1_Numbers_try_it_yourself_page29.py">Try It Your Self Excersise File Page 25</a> <br><br>
<h2>Comments</h2>
<samp>
# Say hello to everyone.
print("Hello Python people!")
</samp>
<h1>Chapter 3</h1>
<span class="note">
If you ask Python to print a list, Python returns its
representation of the list, including the square brackets:
</span>
<span class="term">
position , index
</span>
<span class="note">
list position start at 0
</span>
<span class="trick">
Using this counting system, you can get
any element you want from a list by
subtracting one from its position in the list
</span>
<span class="note">
python support negative positioning starting from -1
</span>
<!-- ######### list.append ######### -->
<section class="object_method">
<!-- Part 1 -->
<span class="defenition">
<span class="object">list</span>
<span class="seprator">.</span>
<span class="method">insert</span>
<span class="arguments">
<span data-argument-type="required"
class="argument">index number</span>
,
<span data-argument-type="required"
class="argument">object</span>
</span>
</span>
<!-- Part 2 -->
<span class="describtion">
<span class="describtion__statement">
<span class="statement__return">nothing</span>
<span class="statement__do">
add
<span class="statement__do__argument">object</span>
to the end of list
</span>
</span>
<span class="describtion__error" data-for-id="list-append-1" >
</span>
</span>
</section>
<!-- ######### list.pop ######### -->
<section class="object_method">
<!-- Part 1 -->
<span class="defenition">
<span class="object">list</span>
<span class="seprator">.</span>
<span class="method">pop</span>
<span class="arguments" >
{
<span class="argument"> </span>
|
<span class="argument">index number</span>
}
</span>
</span>
<!-- Part 2 -->
<span class="describtion">
<span class="describtion__statement">
<span class="statement--argument"> </span>
<span class="statement__return">poped item</span>
<span class="statement__do">
delete last item in list and return it
</span>
</span>
<span class="describtion__statement">
<span class="statement--argument">index number</span>
<span class="statement__return">poped item</span>
<span class="statement__do">
delete
<span class="statement__do__argument" >index number</span>
item in list and return it
</span>
</span>
<span class="describtion__error" data-for-id="list-append-1" >
if you enter wrong
<span class="statement__do__argument" >index number</span>
you get with
<span class="describtion__error--error">index Error</span>
</span>
</span>
</section>
<section>
<var>del</var> keyword
</section>
<!-- ######### list.pop ######### -->
<section class="object_method">
<!-- Part 1 -->
<span class="defenition">
<span class="object">list</span>
<span class="seprator">.</span>
<span class="method">remove</span>
<span class="arguments" >
<span data-argument-type="required" class="argument">object</span>
</span>
</span>
<!-- Part 2 -->
<span class="describtion">
<span class="describtion__statement">
<span class="statement--argument"></span>
<span class="statement__return">N</span>
<span class="statement__do">
delete first
<span class="statement__do__argument">object</span>
that maches
</span>
</span>
</section>
<!-- ######### list.pop ######### -->
<section class="object_method">
<!-- Part 1 -->
<span class="defenition">
<span class="object">list</span>
<span class="seprator">.</span>
<span class="method">remove</span>
<span class="arguments" >
<span data-argument-type="required" class="argument">object</span>
</span>
</span>
<!-- Part 2 -->
<span class="describtion">
<span class="describtion__statement">
<span class="statement--argument">object</span>
<span class="statement__return">N</span>
<span class="statement__do">
delete first
<span class="statement__do__argument">object</span>
that maches
</span>
</span>
</section>
<!-- ######### list.remove ######### -->
<section class="object_method">
<!-- Part 1 -->
<span class="defenition">
<span class="object">list</span>
<span class="seprator">.</span>
<span class="method">sort</span>
<span class="arguments" >
<span data-argument-type="optional" class="argument">reverse = True</span>
</span>
</span>
<!-- Part 2 -->
<span class="describtion">
<span class="describtion__statement">
<span class="statement--argument"></span>
<span class="statement__return">N</span>
<span class="statement__do">
sort and change list permanently
</span>
</span>
</section>
<!-- ######### sort ######### -->
<section class="object_method">
<!-- Part 1 -->
<span class="defenition">
<span class="method">sort</span>
<span class="arguments" >
<span data-argument-type="optional" class="argument">reverse = True</span>
</span>
</span>
<!-- Part 2 -->
<span class="describtion">
<span class="describtion__statement">
<span class="statement--argument"></span>
<span class="statement__return">sorted list</span>
<span class="statement__do">
sort
<span class="statement__do__argument">list</span>
and return sorted list but no change in actual list
</span>
</span>
</section>
<!-- ######### list.reverse ######### -->
<section class="object_method">
<!-- Part 1 -->
<span class="defenition">
<span class="object">list</span>
<span class="seprator">.</span>
<span class="method">reverse</span>
<span class="arguments" >
</span>
</span>
<!-- Part 2 -->
<span class="describtion">
<span class="describtion__statement">
<span class="statement--argument"></span>
<span class="statement__return">N</span>
<span class="statement__do">
reverse list permanently
</span>
</span>
</section>
<!-- ######### list.reverse ######### -->
<section class="object_method">
<!-- Part 1 -->
<span class="defenition">
<span class="method">len</span>
<span class="arguments" >
{
<span class="argument">list</span>
|
<span class="argument">string</span>
}
</span>
</span>
<!-- Part 2 -->
<span class="describtion">
<span class="describtion__statement">
<span class="statement--argument"></span>
<span class="statement__return">length of the
<span class="statement__do__argument">list</span>
|
<span class="statement__do__argument">string</span>
</span>
<span class="statement__do">
N
</span>
</span>
</section>
<section>
IndexError
<code>
motorcycles = ['honda', 'yamaha', 'suzuki']
print(motorcycles[3])
</code>
<samp>
Traceback (most recent call last):
File "motorcycles.py", line 2, in <module>
print(motorcycles[3])
IndexError: list index out of range
</samp>
</section>
<section>
best practice :
check if list empty or not for using <span class="red">LIST[-1]</span>
</section>
<samp>
for <span class="argument1">variable</span> in <span class="argument1">list</span>:
 // do this codes
</samp>
<section>logical error</section>
<setion>
range(a,b) function generate series of number from a to b-1
</setion>
<section>
off-by-one in programming
</section>
<section>
list(range())
range(5,1,-1)
range(1,6,2)
</section>
<section>
Focus first on writing code that you understand clearly, which does what you want it to do. Then look for more efficient approaches as you review your code
</section>
<section><pre>
min(<span class="argument1">list</span>)
find minimum of list
max(<span class="argument1">list</span>)
find maximum of list
</pre></section>
<section>
list comprehension
</section>
<samp>
squares = [value**2 for value in range(1, 11)] print(squares)
</samp>
<section><pre>
</pre></section>
<samp>
dimensions = (200, 50)
dimensions[0] = 250
Traceback (most recent call last):
File "dimensions.py", line 2, in <module>
dimensions[0] = 250
TypeError: 'tuple' object does not support item assignment
</samp>
<section>
Tuples are technically defined by the presence of a comma; the parentheses make them look neater and more readable. If you want to define a tuple with one element, you need to include a trailing comma:
</section>
<samp>
my_t = (3,)
my_t = 3,
</samp>
<section>
The lines starting at u define the original tuple and print the initial dimensions. At v, we associate a new tuple with the variable dimensions. We then print the new dimensions at w. Python doesn’t raise any errors this time, because reassigning a variable is valid
</section>
<section>
Python Enhancement Proposal (PEP).
<p>PEP 8</p>
</section>
<ul>
<li>indentation</li>
<li>line length</li>
<li>blank lines</li>
</ul>
<section>
Many Python programmers recommend that each line should be less than 80 characters
</section>
<section>
PEP 8 also recommends that you limit all of your comments to
72 characters per line
</section>
<section>
The PEP 8 guidelines for line length are not set in stone, and some teams prefer a 99-character limit. Don’t worry too much about line length in your code as you’re learning, but be aware that people who are working collaboratively almost always follow the PEP 8 guidelines. Most editors allow you to set up a visual cue, usually a vertical line on your screen, that shows you where these limits are.
note
</section>
<section>
if you have five lines of code that build a list, and then another three lines that do something with that list, it’s appropriate to place a blank line between the two sections. However, you should not place three or four blank lines between the two sections
</section>
<section>
Blank lines won’t affect how your code runs, but they will affect the readability of your code. The Python interpreter uses horizontal indentation to interpret the meaning of your code, but it disregards vertical spacing.
</section>
<h1>Chapter 4</h1>
<section>
The lower() function doesn’t change the value that was originally stored in car
</section>
<section>
in keyword
<code>
>>> requested_toppings = ['mushrooms', 'onions', 'pineapple']
>>> 'mushrooms' in requested_toppings
True
</code>
</section>
<section>
not in keyword
<code>
>>>banned_users = ['andrew', 'carolina', 'david']
>>>user = 'marie'
>>>u if user not in banned_users:
True
</code>
</section>
<section>
boolean expression
</section>
<section>
boolean value
</section>
<section>
these you can use Python’s if-elif-else syntax. Python executes only one block in an if-elif-else chain. It runs each conditional test in order until one passes. When a test passes, the code following that test is executed and Python skips the rest of the tests.
</section>
<section>
The else block is a catchall statement. It matches any condition that wasn’t matched by a specific if or elif test, and that can sometimes include invalid or even malicious data.
</section>
<section>
In summary, if you want only one block of code to run, use an if-elifelse chain. If more than one block of code needs to run, use a series of independent if statements
</section>
<h3>Falthy and truthy statements</h3>
<pre>
if age < 4:
is better than:
if age<4:
</pre>
</div><body>
<script src="[email protected]"></script>
<script src="[email protected]"></script>
</html>