Skip to content

Commit f6e3afc

Browse files
edschofieldgitbook-bot
authored andcommitted
GitBook: [master] 16 pages modified
1 parent 1d9ca09 commit f6e3afc

16 files changed

+93
-216
lines changed

README.md

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
# Welcome!
1+
# Introduction
22

3-
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.
64

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.
126

137
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.
148

@@ -24,6 +18,5 @@ This book is licensed under a [Creative Commons Attribution-ShareAlike 4.0 Inter
2418

2519
## Read online
2620

27-
The book is hosted online
28-
[here](https://app.gitbook.com/@pythoncharmers/s/course-preparation/](https://app.gitbook.com/@pythoncharmers/s/course-preparation/).
21+
The book is hosted online [here\]\(https://app.gitbook.com/@pythoncharmers/s/course-preparation/](https://app.gitbook.com/@pythoncharmers/s/course-preparation/).
2922

SUMMARY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Table of contents
22

3-
* [Welcome](README.md)
3+
* [Introduction](README.md)
44
* [What To Expect](what_to_expect.md)
55
* [Background Study](preparation.md)
66
* [About Python](about_python.md)

about_python.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ Remember that once you have properly understood and learn to use one version, yo
7676

7777
For details on differences between Python 2 and Python 3, see:
7878

79-
- [The future of Python 2](http://lwn.net/Articles/547191/)
80-
- [Porting Python 2 Code to Python 3](https://docs.python.org/3/howto/pyporting.html)
81-
- [Writing code that runs under both Python2 and 3](http://python-future.org/compatible_idioms.html)
82-
- [Supporting Python 3: An in-depth guide](http://python3porting.com)
79+
* [The future of Python 2](http://lwn.net/Articles/547191/)
80+
* [Porting Python 2 Code to Python 3](https://docs.python.org/3/howto/pyporting.html)
81+
* [Writing code that runs under both Python2 and 3](http://python-future.org/compatible_idioms.html)
82+
* [Supporting Python 3: An in-depth guide](http://python3porting.com)
8383

8484
## What Programmers Say
8585

control_flow.md

+5-15
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The `if` statement is used to check a condition: _if_ the condition is true, we
1010

1111
Example \(save as `if.py`\):
1212

13-
```py
13+
```python
1414
number = 23
1515
guess = int(input('Enter an integer : '))
1616

@@ -30,7 +30,6 @@ else:
3030
print('Done')
3131
# This last statement is always executed,
3232
# after the if statement is executed.
33-
3433
```
3534

3635
Output:
@@ -51,7 +50,6 @@ Enter an integer : 23
5150
Congratulations, you guessed it.
5251
(but you do not win any prizes!)
5352
Done
54-
5553
```
5654

5755
**How It Works**
@@ -91,7 +89,7 @@ The `while` statement allows you to repeatedly execute a block of statements as
9189

9290
Example \(save as `while.py`\):
9391

94-
```py
92+
```python
9593
number = 23
9694
running = True
9795

@@ -111,7 +109,6 @@ else:
111109
# Do anything else you want to do here
112110

113111
print('Done')
114-
115112
```
116113

117114
Output:
@@ -126,7 +123,6 @@ Enter an integer : 23
126123
Congratulations, you guessed it.
127124
The while loop is over.
128125
Done
129-
130126
```
131127

132128
**How It Works**
@@ -149,12 +145,11 @@ The `for..in` statement is another looping statement which _iterates_ over a seq
149145

150146
Example \(save as `for.py`\):
151147

152-
```py
148+
```python
153149
for i in range(1, 5):
154150
print(i)
155151
else:
156152
print('The for loop is over')
157-
158153
```
159154

160155
Output:
@@ -166,7 +161,6 @@ $ python for.py
166161
3
167162
4
168163
The for loop is over
169-
170164
```
171165

172166
**How It Works**
@@ -197,14 +191,13 @@ An important note is that if you _break_ out of a `for` or `while` loop, any cor
197191

198192
Example \(save as `break.py`\):
199193

200-
```py
194+
```python
201195
while True:
202196
s = input('Enter something : ')
203197
if s == 'quit':
204198
break
205199
print('Length of the string is', len(s))
206200
print('Done')
207-
208201
```
209202

210203
Output:
@@ -221,7 +214,6 @@ Enter something : use Python!
221214
Length of the string is 11
222215
Enter something : quit
223216
Done
224-
225217
```
226218

227219
**How It Works**
@@ -249,7 +241,7 @@ The `continue` statement is used to tell Python to skip the rest of the statemen
249241

250242
Example \(save as `continue.py`\):
251243

252-
```py
244+
```python
253245
while True:
254246
s = input('Enter something : ')
255247
if s == 'quit':
@@ -259,7 +251,6 @@ while True:
259251
continue
260252
print('Input is of sufficient length')
261253
# Do other kinds of processing here...
262-
263254
```
264255

265256
Output:
@@ -273,7 +264,6 @@ Too small
273264
Enter something : abc
274265
Input is of sufficient length
275266
Enter something : quit
276-
277267
```
278268

279269
**How It Works**

data_structures.md

+7-19
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ A class can also have _fields_ which are nothing but variables defined for use w
2222

2323
Example \(save as `ds_using_list.py`\):
2424

25-
```py
25+
```python
2626
# This is my shopping list
2727
shoplist = ['apple', 'mango', 'carrot', 'banana']
2828

@@ -45,7 +45,6 @@ olditem = shoplist[0]
4545
del shoplist[0]
4646
print('I bought the', olditem)
4747
print('My shopping list is now', shoplist)
48-
4948
```
5049

5150
Output:
@@ -61,7 +60,6 @@ Sorted shopping list is ['apple', 'banana', 'carrot', 'mango', 'rice']
6160
The first item I will buy is apple
6261
I bought the apple
6362
My shopping list is now ['banana', 'carrot', 'mango', 'rice']
64-
6563
```
6664

6765
**How It Works**
@@ -90,7 +88,7 @@ Tuples are usually used in cases where a statement or a user-defined function ca
9088

9189
Example \(save as `ds_using_tuple.py`\):
9290

93-
```py
91+
```python
9492
# I would recommend always using parentheses
9593
# to indicate start and end of tuple
9694
# even though parentheses are optional.
@@ -105,7 +103,6 @@ print('Animals brought from old zoo are', new_zoo[2])
105103
print('Last animal brought from old zoo is', new_zoo[2][2])
106104
print('Number of animals in the new zoo is',
107105
len(new_zoo)-1+len(new_zoo[2]))
108-
109106
```
110107

111108
Output:
@@ -118,7 +115,6 @@ All animals in new zoo are ('monkey', 'camel', ('python', 'elephant', 'penguin')
118115
Animals brought from old zoo are ('python', 'elephant', 'penguin')
119116
Last animal brought from old zoo is penguin
120117
Number of animals in the new zoo is 5
121-
122118
```
123119

124120
**How It Works**
@@ -132,7 +128,7 @@ We can access the items in the tuple by specifying the item's position within a
132128
> **Tuple with 0 or 1 items**
133129
>
134130
> 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+
>
136132
> **Note for Perl programmers**
137133
>
138134
> 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
151147

152148
Example \(save as `ds_using_dict.py`\):
153149

154-
```py
150+
```python
155151
# 'ab' is short for 'a'ddress'b'ook
156152

157153
ab = {
@@ -176,7 +172,6 @@ ab['Guido'] = '[email protected]'
176172

177173
if 'Guido' in ab:
178174
print("\nGuido's address is", ab['Guido'])
179-
180175
```
181176

182177
Output:
@@ -192,7 +187,6 @@ Contact Matsumoto at [email protected]
192187
Contact Larry at [email protected]
193188
194189
Guido's address is [email protected]
195-
196190
```
197191

198192
**How It Works**
@@ -223,7 +217,7 @@ The three types of sequences mentioned above - lists, tuples and strings, also h
223217

224218
Example \(save as `ds_seq.py`\):
225219

226-
```py
220+
```python
227221
shoplist = ['apple', 'mango', 'carrot', 'banana']
228222
name = 'swaroop'
229223

@@ -247,7 +241,6 @@ print('characters 1 to 3 is', name[1:3])
247241
print('characters 2 to end is', name[2:])
248242
print('characters 1 to -1 is', name[1:-1])
249243
print('characters start to end is', name[:])
250-
251244
```
252245

253246
Output:
@@ -269,7 +262,6 @@ characters 1 to 3 is wa
269262
characters 2 to end is aroop
270263
characters 1 to -1 is waroo
271264
characters start to end is swaroop
272-
273265
```
274266

275267
**How It Works**
@@ -337,7 +329,7 @@ Generally, you don't need to be worried about this, but there is a subtle effect
337329

338330
Example \(save as `ds_reference.py`\):
339331

340-
```py
332+
```python
341333
print('Simple Assignment')
342334
shoplist = ['apple', 'mango', 'carrot', 'banana']
343335
# mylist is just another name pointing to the same object!
@@ -361,7 +353,6 @@ del mylist[0]
361353
print('shoplist is', shoplist)
362354
print('mylist is', mylist)
363355
# Notice that now the two lists are different
364-
365356
```
366357

367358
Output:
@@ -374,7 +365,6 @@ mylist is ['mango', 'carrot', 'banana']
374365
Copy by making a full slice
375366
shoplist is ['mango', 'carrot', 'banana']
376367
mylist is ['carrot', 'banana']
377-
378368
```
379369

380370
**How It Works**
@@ -395,7 +385,7 @@ The strings that you use in programs are all objects of the class `str`. Some us
395385

396386
Example \(save as `ds_str_methods.py`\):
397387

398-
```py
388+
```python
399389
# This is a string object
400390
name = 'Swaroop'
401391

@@ -411,7 +401,6 @@ if name.find('war') != -1:
411401
delimiter = '_*_'
412402
mylist = ['Brazil', 'Russia', 'India', 'China']
413403
print(delimiter.join(mylist))
414-
415404
```
416405

417406
Output:
@@ -422,7 +411,6 @@ Yes, the string starts with "Swa"
422411
Yes, it contains the string "a"
423412
Yes, it contains the string "war"
424413
Brazil_*_Russia_*_India_*_China
425-
426414
```
427415

428416
**How It Works**

0 commit comments

Comments
 (0)