Python Slicing of Strings:
1) slice means a piece
2) [ ] operator is called slice operator, which can be used to retrieve parts of String.
3) In Python Strings follows zero based index.
4) The index can be either +ve or -ve.
5) +ve index means forward direction from Left to Right
6) -ve index means backward direction from Right to Left
>>> s="durga"
>>> s[0]
'd'
>>> s[1]
'u'
>>> s[-1]
'a'
>>> s[40]
>>> s[1:40]
'urga'
>>> s[1:]
'urga'
>>> s[:4]
'durg'
>>> s[:]
'durga'
>>>
>>> s*3
'durgadurgadurga'
>>> len(s)
5
Note:
1) In Python the following data types are considered as Fundamental Data types
- int
- float
- complex
- bool
- str
2) In Python, we can represent char values also by using str type and explicitly char type is not available.
1) >>> c='a'
2) >>> type(c)
3) <class 'str'>