Indexing and slicing operation in sequences

Explain indexing and slicing operation in sequences

- Different types of sequences in python are strings, Unicode strings, lists, tuples, buffers, and xrange objects
- Slicing & indexing operations are salient features of sequence.
- Indexing operation allows to access a particular item in the sequence directly ( similar to the array/list indexing) and the slicing operation allows to retrieve a part of the sequence.
- The slicing operation is used by specifying the name of the sequence followed by an optional pair of numbers separated by a colon within square brackets say S[startno.:stopno].
- The startno in the slicing operation indicates the position from where the slice starts and the stopno indicates where the slice will stop at.
- If the startno is ommited, Python will start at the beginning of the sequence. If the stopno is ommited, Python will stop at the end of the sequence..
- Following code will further explain indexing & slicing operation:
>>> cosmeticList =[‘lipsstick’,’facepowder’,eyeliner’,’blusher’,kajal’]
>>> print “Slicing operation :”,cosmeticList[2:]
Slicing operation :[‘eyeliner’,’blusher’,kajal’]
>>>print “Indexing operation :”,cosmeticList[0]
“Indexing operation :lipsstick
What is a Lambda form?
The lambda form: Using lambda keyword tiny anonymous functions can be created.......
Role of repr function
Role of repr function - Python can convert any value to a string by making use of two functions repr() or str(). .......
Pickling and unpickling
Pickling and unpickling - pickle is a standard module which serializes & de-serializes a python object structure........
Post your comment