Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 42ecd87

Browse files
khanhnnvngitbook-bot
authored andcommitted
GitBook: [master] 9 pages modified
1 parent 3268d87 commit 42ecd87

8 files changed

Lines changed: 348 additions & 17 deletions
File renamed without changes.

3.-an-informal-introduction-to-python.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
description: [email protected]
3+
---
4+
15
# 3. An Informal Introduction to Python
26

37

4.-more-control-flow-tools.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
description: [email protected]
3+
---
4+
15
# 4. More Control Flow Tools
26

37

5.-data-structures.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
# 5. Cấu trúc dữ liệu
1+
---
2+
description: [email protected]
3+
---
24

3-
Phần này sẽ mô tả những gì bạn đã học qua và đi sâu hơn, bổ sung một số phần mới nữa nhé!
5+
# 5. Data Structures
46

5-
### 5.1. Nhiều hơn về Lists
7+
Phần này sẽ mô tả những gì bạn đã học qua và đi sâu hơn, bổ sung một số phần mới nữa nhé!
8+
9+
## 5.1. Nhiều hơn về Lists
610

711
Kiểu dữ liệu list có khá nhiều phương thức để xử lý. Sau đây là tất cả các cách ấy:
812

9-
`list.append`\(_x_\) Nối thêm một phần tử vào cuối danh sách. Tương tự như là `a[len(a):] = [x]`.`list.extend`\(_iterable_\)
13+
`list.append`\(_x_\) Nối thêm một phần tử vào cuối danh sách. Tương tự như là `a[len(a):] = [x]`.`list.extend`\(_iterable_\)
1014

1115
mở rộng danh sách bằng cách thêm tất cả các phần tử từ iterable. Tương tự `a[len(a):] = iterable`.`list.insert`\(_i_, _x_\)
1216

@@ -57,7 +61,7 @@ An example that uses most of the list methods:>>>
5761

5862
You might have noticed that methods like `insert`, `remove` or `sort` that only modify the list have no return value printed – they return the default `None`. [\[1\]](https://docs.python.org/3/tutorial/datastructures.html#id3) This is a design principle for all mutable data structures in Python.
5963

60-
#### 5.1.1. Using Lists as Stacks
64+
### 5.1.1. Using Lists as Stacks
6165

6266
The list methods make it very easy to use a list as a stack, where the last element added is the first element retrieved \(“last-in, first-out”\). To add an item to the top of the stack, use `append()`. To retrieve an item from the top of the stack, use `pop()` without an explicit index. For example:>>>
6367

@@ -79,7 +83,7 @@ The list methods make it very easy to use a list as a stack, where the last elem
7983
[3, 4]
8084
```
8185

82-
#### 5.1.2. Using Lists as Queues
86+
### 5.1.2. Using Lists as Queues
8387

8488
It is also possible to use a list as a queue, where the first element added is the first element retrieved \(“first-in, first-out”\); however, lists are not efficient for this purpose. While appends and pops from the end of list are fast, doing inserts or pops from the beginning of a list is slow \(because all of the other elements have to be shifted by one\).
8589

@@ -98,7 +102,7 @@ To implement a queue, use [`collections.deque`](https://docs.python.org/3/librar
98102
deque(['Michael', 'Terry', 'Graham'])
99103
```
100104

101-
#### 5.1.3. List Comprehensions
105+
### 5.1.3. List Comprehensions
102106

103107
List comprehensions provide a concise way to create lists. Common applications are to make new lists where each element is the result of some operations applied to each member of another sequence or iterable, or to create a subsequence of those elements that satisfy a certain condition.
104108

@@ -189,7 +193,7 @@ List comprehensions can contain complex expressions and nested functions:>&gt
189193
['3.1', '3.14', '3.142', '3.1416', '3.14159']
190194
```
191195

192-
#### 5.1.4. Nested List Comprehensions
196+
### 5.1.4. Nested List Comprehensions
193197

194198
The initial expression in a list comprehension can be any arbitrary expression, including another list comprehension.
195199

@@ -245,7 +249,7 @@ In the real world, you should prefer built-in functions to complex flow statemen
245249

246250
See [Unpacking Argument Lists](https://docs.python.org/3/tutorial/controlflow.html#tut-unpacking-arguments) for details on the asterisk in this line.
247251

248-
### 5.2. The [`del`](https://docs.python.org/3/reference/simple_stmts.html#del) statement
252+
## 5.2. The [`del`](https://docs.python.org/3/reference/simple_stmts.html#del) statement
249253

250254
There is a way to remove an item from a list given its index instead of its value: the [`del`](https://docs.python.org/3/reference/simple_stmts.html#del) statement. This differs from the `pop()` method which returns a value. The [`del`](https://docs.python.org/3/reference/simple_stmts.html#del) statement can also be used to remove slices from a list or clear the entire list \(which we did earlier by assignment of an empty list to the slice\). For example:>>>
251255

@@ -270,7 +274,7 @@ There is a way to remove an item from a list given its index instead of its valu
270274

271275
Referencing the name `a` hereafter is an error \(at least until another value is assigned to it\). We’ll find other uses for [`del`](https://docs.python.org/3/reference/simple_stmts.html#del) later.
272276

273-
### 5.3. Tuples and Sequences
277+
## 5.3. Tuples and Sequences
274278

275279
We saw that lists and strings have many common properties, such as indexing and slicing operations. They are two examples of _sequence_ data types \(see [Sequence Types — list, tuple, range](https://docs.python.org/3/library/stdtypes.html#typesseq)\). Since Python is an evolving language, other sequence data types may be added. There is also another standard sequence data type: the_tuple_.
276280

@@ -322,7 +326,7 @@ The statement `t = 12345, 54321, 'hello!'` is an example of _tuple packing_: the
322326

323327
This is called, appropriately enough, _sequence unpacking_ and works for any sequence on the right-hand side. Sequence unpacking requires that there are as many variables on the left side of the equals sign as there are elements in the sequence. Note that multiple assignment is really just a combination of tuple packing and sequence unpacking.
324328

325-
### 5.4. Sets
329+
## 5.4. Sets
326330

327331
Python also includes a data type for _sets_. A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference.
328332

@@ -363,7 +367,7 @@ Similarly to [list comprehensions](https://docs.python.org/3/tutorial/datastruct
363367
{'r', 'd'}
364368
```
365369

366-
### 5.5. Dictionaries
370+
## 5.5. Dictionaries
367371

368372
Another useful data type built into Python is the _dictionary_ \(see [Mapping Types — dict](https://docs.python.org/3/library/stdtypes.html#typesmapping)\). Dictionaries are sometimes found in other languages as “associative memories” or “associative arrays”. Unlike sequences, which are indexed by a range of numbers, dictionaries are indexed by _keys_, which can be any immutable type; strings and numbers can always be keys. Tuples can be used as keys if they contain only strings, numbers, or tuples; if a tuple contains any mutable object either directly or indirectly, it cannot be used as a key. You can’t use lists as keys, since lists can be modified in place using index assignments, slice assignments, or methods like `append()`and `extend()`.
369373

@@ -417,7 +421,7 @@ When the keys are simple strings, it is sometimes easier to specify pairs using
417421
{'sape': 4139, 'jack': 4098, 'guido': 4127}
418422
```
419423

420-
### 5.6. Looping Techniques
424+
## 5.6. Looping Techniques
421425

422426
When looping through dictionaries, the key and corresponding value can be retrieved at the same time using the `items()` method.>>>
423427

@@ -494,7 +498,7 @@ It is sometimes tempting to change a list while you are looping over it; however
494498
[56.2, 51.7, 55.3, 52.5, 47.8]
495499
```
496500

497-
### 5.7. More on Conditions
501+
## 5.7. More on Conditions
498502

499503
The conditions used in `while` and `if` statements can contain any operators, not just comparisons.
500504

@@ -517,7 +521,7 @@ It is possible to assign the result of a comparison or other Boolean expression
517521

518522
Note that in Python, unlike C, assignment cannot occur inside expressions. C programmers may grumble about this, but it avoids a common class of problems encountered in C programs: typing `=` in an expression when `==`was intended.
519523

520-
### 5.8. Comparing Sequences and Other Types
524+
## 5.8. Comparing Sequences and Other Types
521525

522526
Sequence objects may be compared to other objects with the same sequence type. The comparison uses _lexicographical_ ordering: first the first two items are compared, and if they differ this determines the outcome of the comparison; if they are equal, the next two items are compared, and so on, until either sequence is exhausted. If two items to be compared are themselves sequences of the same type, the lexicographical comparison is carried out recursively. If all items of two sequences compare equal, the sequences are considered equal. If one sequence is an initial sub-sequence of the other, the shorter sequence is the smaller \(lesser\) one. Lexicographical ordering for strings uses the Unicode code point number to order individual characters. Some examples of comparisons between sequences of the same type:
523527

6.-modules.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
description: [email protected]
3+
---
4+
15
# 6. Modules
26

37
If you quit from the Python interpreter and enter it again, the definitions you have made \(functions and variables\) are lost. Therefore, if you want to write a somewhat longer program, you are better off using a text editor to prepare the input for the interpreter and running it with that file as input instead. This is known as creating a _script_. As your program gets longer, you may want to split it into several files for easier maintenance. You may also want to use a handy function that you’ve written in several programs without copying its definition into each program.

7.-input-and-output.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
---
2+
description: [email protected]
3+
---
4+
15
# 7. Input and Output
26

37
There are several ways to present the output of a program; data can be printed in a human-readable form, or written to a file for future use. This chapter will discuss some of the possibilities.

0 commit comments

Comments
 (0)