Delete and Update String

Untitled

In Python, the Update or the Deletion of character from a string is not allowed. This will cause mistake because the determination of item or the removal of the item from String is not supported.

The Update or the Deletion of character from a string is not allowed even though the deletion of entire String is possible with the use the keyword del default.

Untitled

It is because String cannot be changed, so the element of String cannot be changed after determined. Only new string that can be moved to the same name.

Reverse String

By accessing character from a string we also can reverse it. We can reverse string by writing [::-1] and the string will be reversed.

For example:

# Program to reverse a string
msk = "myskill"
print(msk[::-1])
lliksym

Reverse the string using reversed and join function

msk = "myskill"

# Reverse the string using reversed and join function
msk = "".join(reversed(msk))

print(msk)
lliksym

String Slicing