[ lists ]<br />
Defining Lists<br />
* First, you define a list of five elements. Note that they retain their original order. This is not an accident. A list<b...
Negative List Indices<br />Slicing a List<br />
Slicing Shorthand<br />* If the left slice index is 0, you can leave it out, and 0 is implied. So colours[:3] is the same ...
Adding Elements to Lists<br />.append<br />append adds a single element to the end of the list.<br />.extend<br />extend c...
example<br />
The Difference between extend and append<br />
Good Luke  <br />By  salma subh <br /><br />
Upcoming SlideShare
Loading in …5
×

Lists

305 views

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
305
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Lists

  1. 1. [ lists ]<br />
  2. 2. Defining Lists<br />
  3. 3. * First, you define a list of five elements. Note that they retain their original order. This is not an accident. A list<br />is an ordered set of elements enclosed in square brackets.<br />** A list can be used like a zero−based array. The first element of any non−empty list is always names [0].<br />*** The last element of this five−element list is names [4], because lists are always zero−based.<br />
  4. 4. Negative List Indices<br />Slicing a List<br />
  5. 5. Slicing Shorthand<br />* If the left slice index is 0, you can leave it out, and 0 is implied. So colours[:3] is the same as colours[0:3]<br />** Similarly, if the right slice index is the length of the list, you can leave it out. So colours[3:] is the same as colours[3:5], because this list has five elements.<br />
  6. 6. Adding Elements to Lists<br />.append<br />append adds a single element to the end of the list.<br />.extend<br />extend concatenates lists.<br />.insert<br />insert inserts a single element into a list.<br />
  7. 7. example<br />
  8. 8. The Difference between extend and append<br />
  9. 9.
  10. 10. Good Luke  <br />By salma subh <br /><br />

×