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 partition() method.
# Creating a string
s1 = 'Let us rock and roll!'
# Printing the value of string
print('String is : ', s1)
# Calling the partition() method on string
# which will perform the number of splits on the basis of searched value i.e. rock
# and returns a tuple containing all the split values
a_tuple = s1.partition('rock')
# Priting all the split values
print('A tuple of splits : ', a_tuple)
String is : Let us rock and roll!
A tuple splits : ('Let us ', 'rock', ' and roll!')
# Python - Example of partition() method.
# Creating a string
s1 = 'Do not just live, but LIVE your life!'
# Printing the value of string
print('String is : ', s1)
# Calling the partition() method on string
# which will perform the number of splits on the basis of searched lower case value i.e. l
# 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 partition() method on string
# which will perform the number of splits on the basis of searched lower case value i.e. e
# and returns a tuple containing all the split values
tuple1 = s1.partition('e')
# Priting all the split values
print('A tuple split by e : ', tuple1)
# Calling the partition() method on string
# which will perform the number of splits on the basis of searched lower case value i.e. live
# and returns a tuple containing all the split value
tuple3 = s1.partition('live')
# Priting all the split values
print('A tuple split by live : ', tuple3)
# Calling the partition() method on string
# which will perform the number of splits on the basis of searched upper case value i.e. LIVE
# and returns a tuple containing all the split values
tuple4 = s1.partition('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 liv', 'e', ', but LIVE your life!')
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!')
Advertisement
# Python - Example of partition() method.
# Creating a string
s1 = 'Eddie edited a diary!'
# Printing the value of string
print('String is : ', s1)
# Calling the partition() 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.partition('di')
# Priting all the split values
print('A tuple split by di : ', tuple1)
String is : Eddie edited a diary!
A tuple split by di : ('Ed', 'di', 'e edited a diary!')
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement