@@ -183,7 +183,7 @@ print xs[-1] # Negative indices count from the end of the list; prints "2"
183
183
xs[2 ] = ' foo' # Lists can contain elements of different types
184
184
print xs # Prints "[3, 1, 'foo']"
185
185
xs.append(' bar' ) # Add a new element to the end of the list
186
- print xs # Prints
186
+ print xs # Prints "[3, 1, 'foo', 'bar']"
187
187
x = xs.pop() # Remove and return the last element of the list
188
188
print x, xs # Prints "bar [3, 1, 'foo']"
189
189
```
@@ -203,7 +203,7 @@ print nums[:2] # Get a slice from the start to index 2 (exclusive); prints "
203
203
print nums[:] # Get a slice of the whole list; prints ["0, 1, 2, 3, 4]"
204
204
print nums[:- 1 ] # Slice indices can be negative; prints ["0, 1, 2, 3]"
205
205
nums[2 :4 ] = [8 , 9 ] # Assign a new sublist to a slice
206
- print nums # Prints "[0, 1, 8, 8 , 4]"
206
+ print nums # Prints "[0, 1, 8, 9 , 4]"
207
207
```
208
208
We will see slicing again in the context of numpy arrays.
209
209
@@ -385,9 +385,9 @@ We will often define functions to take optional keyword arguments, like this:
385
385
``` python
386
386
def hello (name , loud = False ):
387
387
if loud:
388
- print ' HELLO, %s ' % name.upper()
388
+ print ' HELLO, %s ! ' % name.upper()
389
389
else :
390
- print ' Hello, %s ! ' % name
390
+ print ' Hello, %s ' % name
391
391
392
392
hello(' Bob' ) # Prints "Hello, Bob"
393
393
hello(' Fred' , loud = True ) # Prints "HELLO, FRED!"
0 commit comments