List Slicing & List Operations in python..
List Slicing:
The slicing operator return a subset of list called slice, by specifying start and end indexes.
Syntax:
Creating List without using Constructor:
Output:
List slicing with step-size:
The third parameter step-size is to select list with step-size.>
Syntax:
Example:
Output:
List Operations:
Traversing a List:
To traverse a list we use "for in" statement which make it easy to look over the item in a list.
Output:
If we need both index and item, we use enumerate function.
Output:
If we need only index, we can use range and len function.
Output:
For shortcut list operations, we use built in Functions
Comments
Post a Comment