ABOUT STRING METHODS
STRING METHODS :- String methods are tools to perform particular functionality. In string method it returns a new string instead of changing the orginal string.
String Methods are written in syntax. The syntax used to write string method is string. method name( ) .
String methods are Upper( ) , Lower( ) , Swapcase( ) , Capitalize( ) , title( ) , count( ) , replace( ) , index( ) , rindex( ) , find( ) , r.find( ) , strip( ) , lstrip( ) , rstrip( ) , split( ) , rsplit( ) , partition ( ) , rpartiton( ) .
1) Upper( ) :-
Upper ( ) will convert lower case character into upper case and rest of the characters will be ignored .
String.upper( )
It returns the new string because strings are immutable.
2) Lower( ):-
Lower ( ) will convert upper case character into lower case character and rest of the characters will be ignored.
String.lower( )
It returns the new string.
3)Swapcase( ):-
Swapcace( ) will convert lower case characters into upper case characters and upper case characters into lower case characters.
String.swapcase( )
It returns the new string.
4)Capitalize( ):-
Capitalize( ) will converts first character into upper case in a string if it is lower case characters and rest of characters will convert to lower case characters if it is upper case characters.
String.Capitalize ( )
It returns the new string.
5)Title ( ):-
Title ( ) will converts the first character of a word’s in a string from lower case characters to upper case characters and rest of the characters will be ignored. Gives importance to all the words inside string. It changes the first letter of the words in a string to upper case and rest of the characters will turns into lower case alphabets.
Sting.title ( )
It returns in a new string.
6)Count( ):-
Count( ) will counts the number of sub strings present in a string .
String.count ( “ ”,starting index , Ending index)
Here python moves from left to right if we forcefully moves from right to left it will gives output as “empty” as “0”.
It is not a string , it would be an integer.
7)replace( ):-
In replace( ) we can replace original substring with new substring from a string.
String.replace(orginal substring, new substring , max limit )
Original substring = SubString which is present in sring.
New substring = Substring which we need to replace original substring in a string.
Max limit : At which index we can replace the new substring.
Get SHASHANK SAI RAJ’s stories in your inbox
Join Medium for free to get updates from this writer.
It returns in a new string.
8)index ( ):-
Index( ) used to return the location of a substring occurring in the first occurrence of a string.
String.index(substring,starting index,Ending index)
It doesn’t gives you a string it gives an integer. Here python moves from left to right if we given input to move from right to left it gives error .If the substring is not found in a string it gives value error.
9)rindex( ):-
rindex( ) is same as index( ) but in this it prefers from right to left in a string to find a substring. It gives output from last occurrence.
10)find( ):-
find( ) used to return the location of a substring occurring in the first occurrence of a string.
String.index(substring,starting index,Ending index)
It doesn’t gives you a string it gives an integer. Here python moves from left to right if we given input to move from right to left it gives output as -1.If the substring is not found in a string it gives output as -1.
11)rfind( ):-
rfind( ) is same as find( ) but in this it prefers from right to left in a string to find a substring. It gives output from last occurrence.
12)strip( ):-
Strip( ) will remove the character or elements of starting and ending of a string . If we doesn’t use any character inside the string then default character will be space. It’s not take as substring or any sequence of elements. It takes as seperate characters of each.Here it doesn’t remove the substring in the middle of the string.
String.string (substring)
Here strip is classified into two types
1)lstrip( )
2)rstrip( )
13)lstrip( ):-
lstrip( ) is same as strip( ) but in lstrip( ) it only removes the character which are at left side of the string.
14)rstrip( ):-
rstrip( ) is same as strip( ) but in rstrip( ) it only removes the character which are at right side of the string.
15)split( ):-
Split( ) will split your entire string into a substring . Based on the condition it splits the string. Here default is space .If we have one element to split it gives space toward left of the element and it gives space towards right side of the element and removes the element which we splits and these executes it as Output .
String.split(substring,no.of same elements need to split)
It removes the element before the index.
16)rsplit:-
rsplit( ) is same as split( ) but it will removes the elements from right to the left of the string.
17)partition( ):-
Partition ( ) will split the string into a substring in the form of 3types and it executes as Before split, split value and After split. Here we doesn’t get space as default.
String.partition(Before split value,Split value,After split value)
18)rpartition:-
rpartition( ) is same as partition( ) it will split from right to left in a string.
— — — — — — — — — — — -************************* — — — — — — — — — — -









