Which of the following functions will return the always a Tuple of 3 elements?
(a) Find ( ) (b) Index ( )
(c) Partition ( ) (d) Split ( )
Answers
Hope it will help you
Option c : partition() function always return a tuple of 3 elements.
More about functions :
a) find() : The find() function returns the index of the first occurrence of the substring is found. If not found, then it returns -1.
Example :
str = "I love car."
index = str.find('love')
print("Substring 'love' : ", index)
b) index() : The index() function returns the index of the given element in the list.
Example :
L = [10 , 12 , 23 , 34 , 45]
index = L.index(12)
print("Index of 12 is ",index)
c) partition() : The partition() function splits the string at the first occurrence of the given string and always return a tuple containing three parts :
- String before separator
- Given string
- String after separator.
str = "I live in Lucknow."
print(str.partition('in')
d) split() : The split() function returns a list of the words in the string/line, separated by a delimiter string.
Example :
str = "I love to play football."
print(str.split(" ",3))