Advertisement
partition(value)
Parameters | Description |
---|---|
value | This is the value to be searched in the invoked string and on the basis of it a tuple of three values will be created, only if this value is found. |
# Python - Example of rpartition() method.
# Creating a string
s1 = 'Do you like rock n rock or hard rock or jazz?'
# Printing the value of string
print('String is : ', s1)
# Calling the rpartition() method on string
# which will perform the number of splits on the basis of searched value i.e. rock
# searching starts at the right of the string
# and returns a tuple containing all the split values
a_tuple = s1.rpartition('rock')
# Priting all the split values
print('A tuple of splits : ', a_tuple)
String is : Do you like rock n rock or hard rock or jazz?
A tuple of splits : ('Do you like rock n rock or hard ', 'rock', ' or jazz?')
Advertisement
# Python - Example of rpartition() method.
# Creating a string
s1 = 'Do not just live, but LIVE your life!'
# Printing the value of string
print('String is : ', s1)
# Calling the rpartition() method on string
# which will perform the number of splits on the basis of searched lower case value i.e. l
# searching starts at the right of the string
# and returns a tuple containing all the split values
tuple1 = s1.partition('l')
# Priting all the split values
print('A tuple split by l : ', tuple1)
# Calling the rpartition() method on string
# which will perform the number of splits on the basis of searched lower case value i.e. e
# searching starts at the right of the string
# and returns a tuple containing all the split values
tuple1 = s1.rpartition('e')
# Priting all the split values
print('A tuple split by e : ', tuple1)
# Calling the rpartition() method on string
# which will perform the number of splits on the basis of searched lower case value i.e. live
# searching starts at the right of the string
# and returns a tuple containing all the split values
tuple3 = s1.rpartition('live')
# Priting all the split values
print('A tuple split by live : ', tuple3)
# Calling the rpartition() method on string
# which will perform the number of splits on the basis of searched upper case value i.e. LIVE
# searching starts at the right of the string
# and returns a tuple containing all the split values
tuple4 = s1.rpartition('LIVE')
# Priting all the split values
print('A tuple split by LIVE : ', tuple4)
String is : Do not just live, but LIVE your life!
A tuple split by l : ('Do not just ', 'l', 'ive, but LIVE your life!')
A tuple split by e : ('Do not just live, but LIVE your lif', 'e', '!')
A tuple split by live : ('Do not just ', 'live', ', but LIVE your life!')
A tuple split by LIVE : ('Do not just live, but ', 'LIVE', ' your life!')
# Python - Example of rpartition() method.
# Creating a string
s1 = 'Eddie edited a diary!'
# Printing the value of string
print('String is : ', s1)
# Calling the rpartition() method on string
# which will perform the number of splits on the basis of searched value i.e. di
# and returns a tuple containing all the split values
tuple1 = s1.rpartition('di')
# Priting all the split values
print('A tuple split by di : ', tuple1)
String is : Eddie edited a diary!
A tuple split by di : ('Eddie edited a ', 'di', 'ary!')
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement