changeset 211 | 8bc4f7b3e038 |
parent 208 | 0f78508a4478 |
210:bd7338e67289 | 211:8bc4f7b3e038 |
---|---|
48 list_in_list=[[4,2,3,4],'and', 1, 2, 3, 4] |
48 list_in_list=[[4,2,3,4],'and', 1, 2, 3, 4] |
49 |
49 |
50 We access list elements using the number of index. The |
50 We access list elements using the number of index. The |
51 index begins from 0. So for list nonempty, nonempty[0] gives the |
51 index begins from 0. So for list nonempty, nonempty[0] gives the |
52 first element, nonempty[1] the second element and so on and |
52 first element, nonempty[1] the second element and so on and |
53 nonempty[3] the last element.:: |
53 nonempty[3] the last element. :: |
54 |
54 |
55 nonempty[0] |
55 nonempty[0] |
56 nonempty[1] |
56 nonempty[1] |
57 nonempty[3] |
57 nonempty[3] |
58 |
58 |
63 nonempty[-4] |
63 nonempty[-4] |
64 |
64 |
65 -1 gives the last element which is the 4th element , -2 second to last and -4 gives the fourth |
65 -1 gives the last element which is the 4th element , -2 second to last and -4 gives the fourth |
66 from last element which is first element. |
66 from last element which is first element. |
67 |
67 |
68 |
|
69 |
|
70 |
|
71 We can append elements to the end of a list using append command. :: |
68 We can append elements to the end of a list using append command. :: |
72 |
69 |
73 nonempty.append('onemore') |
70 nonempty.append('onemore') |
74 nonempty |
71 nonempty |
75 nonempty.append(6) |
72 nonempty.append(6) |
78 As we can see non empty appends 'onemore' and 6 at the end. |
75 As we can see non empty appends 'onemore' and 6 at the end. |
79 |
76 |
80 |
77 |
81 |
78 |
82 Using len function we can check the number of elements in the list |
79 Using len function we can check the number of elements in the list |
83 nonempty. In this case it being 6: |
80 nonempty. In this case it being 6 :: |
84 |
81 |
85 len(nonempty) |
82 len(nonempty) |
86 |
83 |
87 |
84 |
88 |
85 |
132 I hope you found this tutorial useful. |
129 I hope you found this tutorial useful. |
133 |
130 |
134 Thank You |
131 Thank You |
135 |
132 |
136 |
133 |
137 Author : Amit Sethi |
134 * Author : Amit Sethi |
138 First Reviewer : |
135 * First Reviewer : |
139 Second Reviewer : Nishanth |
136 * Second Reviewer : Nishanth |