PYTHON STRING OPERATIONS
##Note-- the methods which contains *(star) with their names are important because
those are commonly used methods
Python provides a set of built-in methods to alter and modify the strings
**1.upper()-- converts string into uppercase.
**2. lower()-- converts strings into lowercase.
**3. strip()-- this method removes any white spaces from before and after of the
string.
**4. rstrip()-- this method removes any trailing characters. {ex. [Anmolllll],
trailing character is 'l ' in the string (repeated character)}
**5. replace()-- this method removes any desired character or the whole word and
sentence and places A new given word or character or sentence.
{example "Anmol"
replace("Anmol","jack"
then new word will be jack}
**6.split()-- this method can split the given string at the specified instance and
returns the seperated string into list items.
{
example--
a = "Anmol Trivedi"
a.split(" ") -- splits the string from the space portion--
}
**7. capitalize()-- this method capitalizes the first word of the string and
changes other words into lowercase.
**8. center()-- this method aligns the string to the center as per the paramters
given by the user.
**9. count()-- this method counts the number of characters in the string and
provides the answer
{
example--
a = "Anmol"
a.count() = 5 (the word contains 5 letters)
}
10. endswith()-- this methods checks whether the string with the word which you
gave or not. if the string is ending with that particular character , then it will
return true, otherwise false.
{
example
a = "snow"
a.endswith(w) -- returns true
a.endswith(o)--- returns false
}
**11. find()-- this method searches for the first occurence of the given value and
returns the index where it is presented. if the given value is not presented in the
list then it will return (-1)
example
a = "snooker"
a.find("k")---- returns 4\
***12. isalpha()---- this method returns true only if the entire string is consist
of A-Z, or a-z, (only letters). if any other characters (special characters (@,#) ,
numbers (0-9), punctuations (,;'") are present in the string then it returns
false.
13. islower()---- returns true only if all the characters present will be in small
letters, otherwise returns false.
14. isprintable()---- this method returns true only if all the characters present
in the string are printable. i not, then returns false.
a = "hello" --- returns true.
a = "hello \n" --- returns false (\n is not a printable character).
15. isspace()---- this method only returns true if the string contains white spaces
(space between words) , otherwise returns false.
16. istitle()---- returns true only if the first letter of each word of the string
is capital, otherwise returns false.
17. startswith()---- the method checks if the string is starting with the given
word, if it satisfies the condition, then returns true, else returns false.
***18. swapcase()---- this method converts the cases of the string, if string is in
uppercase, then it converts it into lowercase, and if string is in lowercase then
it converts it into uppercase.
***19. title() ---- this methods capitalizes the first character of each word
present in the string
a = i am a human
a.title() = I Am A Human