-
-
Save IndhumathyChelliah/8f764f22b629f808afac70855a4d929b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Only one occurence of seperator is there. | |
s1="Python string methods" | |
print (s1.partition("string"))#Output:('Python ', 'string', ' methods') | |
print (s1.rpartition("string"))#Output:('Python ', 'string', ' methods') | |
#more than one cocurence of seperator. | |
s2="I like to learn Python.Python is a programming language" | |
print (s2.partition("Python"))#Output:('I like to learn ', 'Python', '.Python is a programming language') | |
print (s2.rpartition("Python"))#Output:('I like to learn Python.', 'Python', ' is a programming language') | |
#it is case sensitive. search for the exact seperator. | |
print (s2.partition("python"))#Output:('I like to learn Python.Python is a programming language', '', '') | |
#seperator is not found in the string. | |
s3="Hello world!" | |
print (s3.partition("hi"))#Output:('Hello world!', '', '') | |
print (s3.rpartition("hi"))#Output:('', '', 'Hello world!') | |
#If seperator is not mentioned,raises TypeError | |
#print (s3.partition())#Output:TypeError: partition() takes exactly one argument (0 given) | |
#print (s3.rpartition())#Output:TypeError: rpartition() takes exactly one argument (0 given) | |
s4="12325" | |
print (s4.partition("2"))#Output:('1', '2', '325') | |
print (s4.rpartition("2"))#Output:('123', '2', '5') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment