Advertisement
count(value, start, end)
Parameters | Description |
---|---|
separator | This optional parameter is a string value, which acts a separator, used to split the values of the invoked string. The default separator is white space. |
maxnumber | This optional parameter is an integer value, used to specify the maximum number of splits to perform. Its default value is -1 i.e. a split for each occurrence of separator value. |
# Python - Example of rsplit() method.
# Creating a string
s1 = 'Life is what you make out of it!'
# Printing the value of string
print('String is : ', s1)
# Calling the rsplit() method on string
# which will perform the number of splits(starting at the right)
# on the basis of default separator i.e. white space
# and returns a list containing all the split values
a_list = s1.rsplit()
# Priting all the split values
print('A list of splits : ', a_list)
String is : Life is what you make out of it!
A list of splits : ['Life', 'is', 'what', 'you', 'make', 'out', 'of', 'it!']
Advertisement
# Python - Example of rsplit() method.
# Creating a string
s1 = 'Tomorrow never comes, All we have is NOW!'
# Printing the value of string
print('String is : ', s1)
# Calling the rsplit() method on string
# which will perform the number of splits on the basis of separator upper case 'A'
a_list = s1.rsplit('A')
# Priting all the spiits
print('Number of splits when the separator is A : ', a_list)
# Calling the rsplit() method on string
# which will perform the number of splits on the basis of separator lower case 'e'
# used by the rsplit() method i.e. white space
a_list = s1.rsplit('e')
# Priting all the spiits
print('Number of splits when the separator is e :', a_list)
# Calling the rsplit() method on string
# which will perform the number of splits on the basis of separator ','
# used by the rsplit() method i.e. white space
a_list = s1.rsplit(',')
# Priting all the spiits
print('Number of splits when the separator is , :', a_list)
# Calling the rsplit() method on string
# which will perform the number of splits on the basis of separator lower case 'n'
# used by the rsplit() method i.e. white space
a_list = s1.rsplit('n')
# Priting all the spiits
print('Number of splits when the separator is n :', a_list)
# Calling the rsplit() method on string
# which will perform the number of splits on the basis of separator lower case 'N'
# used by the rsplit() method i.e. white space
a_list = s1.rsplit('N')
# Priting all the spiits
print('Number of splits when the separator is N :', a_list)
String is : Tomorrow never comes, All we have is NOW!
Number of splits when the separator is A : ['Tomorrow never comes, ', 'll we have is NOW!']
Number of splits when the separator is e : ['Tomorrow n', 'v', 'r com', 's, All w', ' hav', ' is NOW!']
Number of splits when the separator is , : ['Tomorrow never comes', ' All we have is NOW!']
Number of splits when the separator is n : ['Tomorrow ', 'ever comes, All we have is NOW!']
Number of splits when the separator is N : ['Tomorrow never comes, All we have is ', 'OW!']
# Python - Example of rsplit() method.
# Creating a string
s1 = 'Eddiee edited it'
# Printing the value of string
print('String is : ', s1)
# Calling the rsplit() method on string, starting from the right
# which will perform 2 splits on the basis of separator lower case 'e'
a_list = s1.rsplit('e', 2)
# Priting all the spiits
print('2 Splits when the separator is e : ', a_list)
# Calling the rsplit() method on string, starting from the right
# which will perform 2 splits on the basis of separator lower case 'i'
a_list = s1.rsplit('i', 2)
# Priting all the spiits
print('2 Splits when the separator is i :', a_list)
# Calling the rsplit() method on string, starting from the right
# which will perform 1 split on the basis of separator lower case 't'
a_list = s1.rsplit('t', 1)
# Priting all the spiits
print('1 split when the separator is t :', a_list)
# Calling the rsplit() method on string, starting from the right
# which will perform 2 splits on the basis of separator lower case 'd'
a_list = s1.rsplit('d', 2)
# Priting all the spiits
print('2 Splits when the separator is d :', a_list)
String is : Eddiee edited it
2 Splits when the separator is e : ['Eddiee ', 'dit', 'd it']
2 Splits when the separator is i : ['Eddiee ed', 'ted ', 't']
1 split when the separator is t : ['Eddiee edited i', '']
2 Splits when the separator is d : ['Eddiee e', 'ite', ' it']
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement