01 Python Strings
01 Python Strings
01 Python Strings
Creating a String
Accessing Characters
Negative index -5 -4 -3 -2 -1
String H E L L O
index 0 1 2 3 4
Individual characters of a String can be accessed by using Index. Index number starts at 0 for the 1st
character in the string.
Indexing also allows negative address references to access characters from the back of the String,
e.g. -1 refers to the last character, -2 refers to the second last character, and so on.
String Slicing
To access a range of characters in the String, the method of slicing is used. Slicing in a String is done
by using a Slicing operator (colon).
In Python, Updation or deletion of characters from a String is not allowed. This will cause an error
because item assignment or item deletion from a String is not supported.
Although deletion of the entire String is possible with the use of a built-in del keyword.
This is because Strings are immutable, hence elements of a String cannot be changed once it has been
assigned. Only new strings can be reassigned to the same name.