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
We are delighted that you will be attending a Python training course run by
4
-
[Python Charmers](https://pythoncharmers.com)! These materials describe how best
5
-
to prepare for the course.
3
+
We are delighted that you will be attending a Python training course run by [Python Charmers](https://pythoncharmers.com)! These materials describe how best to prepare for the course.
6
4
7
-
These materials are based on the free online book "A Byte of Python" by Swaroop
8
-
C H but customized by Python Charmers to be optimal as pre-course reading for
9
-
Python Charmers' [Introduction to
10
-
Python](https://pythoncharmers.com/training/introduction-to-python/) course and
11
-
other courses.
5
+
These materials are based on the free online book "A Byte of Python" by Swaroop C H but customized by Python Charmers to be optimal as pre-course reading for Python Charmers' [Introduction to Python](https://pythoncharmers.com/training/introduction-to-python/) course and other courses.
12
6
13
7
It includes a tutorial or introductory guide to the Python language \(version 3\) for a beginner audience. If all you know about computers is how to save text files, then this is the book for you.
14
8
@@ -24,6 +18,5 @@ This book is licensed under a [Creative Commons Attribution-ShareAlike 4.0 Inter
The book is hosted online [here\]\(https://app.gitbook.com/@pythoncharmers/s/course-preparation/](https://app.gitbook.com/@pythoncharmers/s/course-preparation/).
Copy file name to clipboardexpand all lines: data_structures.md
+7-19
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ A class can also have _fields_ which are nothing but variables defined for use w
22
22
23
23
Example \(save as `ds_using_list.py`\):
24
24
25
-
```py
25
+
```python
26
26
# This is my shopping list
27
27
shoplist = ['apple', 'mango', 'carrot', 'banana']
28
28
@@ -45,7 +45,6 @@ olditem = shoplist[0]
45
45
del shoplist[0]
46
46
print('I bought the', olditem)
47
47
print('My shopping list is now', shoplist)
48
-
49
48
```
50
49
51
50
Output:
@@ -61,7 +60,6 @@ Sorted shopping list is ['apple', 'banana', 'carrot', 'mango', 'rice']
61
60
The first item I will buy is apple
62
61
I bought the apple
63
62
My shopping list is now ['banana', 'carrot', 'mango', 'rice']
64
-
65
63
```
66
64
67
65
**How It Works**
@@ -90,7 +88,7 @@ Tuples are usually used in cases where a statement or a user-defined function ca
90
88
91
89
Example \(save as `ds_using_tuple.py`\):
92
90
93
-
```py
91
+
```python
94
92
# I would recommend always using parentheses
95
93
# to indicate start and end of tuple
96
94
# even though parentheses are optional.
@@ -105,7 +103,6 @@ print('Animals brought from old zoo are', new_zoo[2])
105
103
print('Last animal brought from old zoo is', new_zoo[2][2])
106
104
print('Number of animals in the new zoo is',
107
105
len(new_zoo)-1+len(new_zoo[2]))
108
-
109
106
```
110
107
111
108
Output:
@@ -118,7 +115,6 @@ All animals in new zoo are ('monkey', 'camel', ('python', 'elephant', 'penguin')
118
115
Animals brought from old zoo are ('python', 'elephant', 'penguin')
119
116
Last animal brought from old zoo is penguin
120
117
Number of animals in the new zoo is 5
121
-
122
118
```
123
119
124
120
**How It Works**
@@ -132,7 +128,7 @@ We can access the items in the tuple by specifying the item's position within a
132
128
> **Tuple with 0 or 1 items**
133
129
>
134
130
> An empty tuple is constructed by an empty pair of parentheses such as `myempty = ()`. However, a tuple with a single item is not so simple. You have to specify it using a comma following the first \(and only\) item so that Python can differentiate between a tuple and a pair of parentheses surrounding the object in an expression i.e. you have to specify `singleton = (2 , )` if you mean you want a tuple containing the item `2`.
135
-
131
+
>
136
132
> **Note for Perl programmers**
137
133
>
138
134
> A list within a list does not lose its identity i.e. lists are not flattened as in Perl. The same applies to a tuple within a tuple, or a tuple within a list, or a list within a tuple, etc. As far as Python is concerned, they are just objects stored using another object, that's all.
@@ -151,7 +147,7 @@ The dictionaries that you will be using are instances/objects of the `dict` clas
0 commit comments