Professional Documents
Culture Documents
Code Result
\\ Backslash
\n New Line
\r Carriage Return
\t Tab
\b Backspace
\f Form Feed
String slicing
We can store strings in containers example-
Mestr- "Lifebuoy is a good product"
print(Mestr)
WE can check the length of the string by typing-
print(len(mestr))
There is a function in python where we can slice the
strings in to parts. This is based on letters and also the
spaces. These slicing can be done by-
print(mestr[0:4])- which gives the letters from l to e
which are life. We can also leave the space where
we write 0 as it comes from default.
print(mestr[0:26:3])- gives us the letters in the
phrase but leaves 3 letters which will give us leoi ao
oc. If we leave it blank, by default there will be 1.
Other Functions
There are many other functions in python where we can
check, count etc. They are-
print(mestr.endswith(t)) - checks if the string ends
with the letter in the brackets.
print(mestr.isalnum()) - checks if the string is alpha
numeric
print(mestr.isalpha()) - checks if it is alpha
print(mestr.count(i)) - counts how many 'I's are
there in the string