Predefined function in string data type-Part II
Hello, everyone Vrushali here again . You must be gone from my privious article which is predefined function in string data type i.e part-I the link is https://medium.com/@wvrushali27/predefined-functions-in-string-data-type-423ed2cc0b8e. Here we are going with the remaining method of string , so Let’s start Guys!
- join():
Join() is the built in function in string datatype, here join() method used to join element of the sequence seperated by the string seperator.
Syntax:
string.join()
Join() method returns a string concatenated with the element of string operator.
2. ljust():
ljust() method is return a new string of given length. ljust is nothing but the left justify means this method returns a left-justified string of length width.
Syntax:
string.ljust(length, fillchar)
Parameter:
length: length of the modified string. If length is less than or equal to the length of the original string then original string is returned.
fillchar: this the optional one, characters which needs to be padded. If it’s not provided, space is taken as a default argument.
3. lstrip():
In these lstrip() function returns the copy of string leading to remove the whitespaces.If no argument is passed, it removes leading spaces.
Syntax:
string.lstrip()
In the above example we give the string having leading spaces using the lstrip() method we can remove those whitespaces and see the output on line Out[197].
4. partition():
you should know the partition means seperator , this method we also see the seperator of the string.method partition() will search for the seperator in the string. If the seperator is found, it will returns a 3-tuple containing the part i.e before seperator, the seperator and after seperator.
here if the seperator is not found then it will be return a 3 chunks of the string containing string and two empty string.
5. removeprefix():
String removeprefix() is a built-in method present in python. It return a string with the given prefix string removed which is present.
If the string starts with the prefix, the it will remove the prefix character then show the output on screen, otherwise return a copy of the orignal string.
Syntax:
string.removeprefix(prefix)
6. removesuffix():
String removesuffix() method return a string with the given suffix removed if present in the string . If the string ends with the suffix string and suffix is not empty then it will return a suffix removed string, otherwise it return a copy of the original string.
Syntax:
string.removesuffix(suffix)
7. replace():
String replace() method in Python returns a copy of the string where occurrences of a substring are replaced old with new one substring.
In above example the guys is replace by the student using the replace() method.
8.rfind():
String rfind() method returns the rightmost index of the substring if found in the given string. If not found then it returns -1.
Here, we can give the parameter as ‘tude’ which present in string. using rfind() method it will return a highest index in given in parameter string.
9.rindex:
String rindex() method returns the highest index of the substring inside the string if the substring is found. Otherwise, it raises ValueError.
10. rjust():
The string rjust() method returns a new string of given length after substituting a given character in left side of original string.
Get Vrushali Walekar’s stories in your inbox
Join Medium for free to get updates from this writer.
Syntax:
string.rjust(length,fillchar)
length: length of the modified string. If length is less than or equal to the length of the original string then original string is returned.
fillchar: It is a optional characters which needs to be padded. If it’s not provided, space is taken as a default argument.
11. rpartition():
String rpartition() Method split the given string into three parts. rpartition() starts looking separator from the right side, till the separator is found and return a string which contains part of the string before separator, the separator and the part after the separator.
In the input line In[31]: given a seperator as “network” it will be seperate from right side which means fisrt will print from right side string, then found the seperator that is “network” and then print the remain string.
12. rsplit():
String rsplit() method returns a list of strings after breaking the given string from the right side by the specified separator.
Syntax:
string.rsplit(seperator)
Here, separator is nothing but delimiter. The string splits at this specified separator starting from the right side. If not provided then any white space character is a separator.
rsplit() method Returns a string after breaking sring from right side by secified seperator, see the output line Out[34] ,in that first it will print from right side string then it will print sepator space is empty and then print remain string.
13.splitlines():
String splitlines() method is used to split the lines at line boundaries. The function returns a list of lines in the string, including the line break.
syntax:
string.splitlines():
14. startswith():
String startswith() method returns True is string starts with the specified prefix,otherwise it will be false.
syntax:
string.startswith(prefix)
In above example we give the string as ‘good morning’ using the startswith() method, and specifies the prefix as ‘good’ it is present in the given string then it returns a true.
15. strip():
String strip() function return a copy of the string with leading whitespace removed.
syntax:
string.strip()
16. swapcase():
String swapcase() method convert the uppercase character to lowercase and lowercase character to uppercase.
syntax:
String.swapcase()
In Following example In [57] “Hello WorLD” is a string having a H,L,D,W which means the uppercase, it will convert into lowercase the string will be “hELLO wORld”.
17. title():
String title() method return a string where each word is titlecased. In this title() method word start with uppercase characters and all remaining characters have lower case.
syntax:
string.title()
18.upper():
String upper() method return a copy of the string converted to uppercase.
Syntax:
string.upper()
In the following example In[64]: the string in lowercase as well as in uppercase using upper() whole string convert into in uppercase.
In this article, we have covered the built-in string functions in Python.
#vevcodelab









