Which of the following invocations are valid? (Choose two.)
Which of the following invocations are valid? (Choose two.)
The function 'sorted()' can be used with any iterable, including strings, and it returns a new sorted list of characters, making 'sorted("python")' valid. The method 'index()' is a valid string method used to find the position of a substring within the string, so '"python".index("th")' is also correct. The 'sort()' method is specific to lists and cannot be applied to strings, making '"python".sort()' invalid. The 'rfind()' method is also incorrect as it is not in the proper format and does not belong to string manipulations.
hey admin, can you correct those signs to correct signs ?
BD is correct
B. sorted("python") D. "python".index("th")
>>> sorted("python") ['h', 'n', 'o', 'p', 't', 'y'] >>> "python".index("th") 2
sorted() is a general-purpose function that can be used with any iterable, including strings, and it returns a new sorted list. sort() is a method specifically for lists, and it sorts the elements of the list in-place. When dealing with strings, you need to convert them to a list to use sort() and then join the characters back together if needed.
Question 86 Which of the following invocations are valid? (Choose two.) respuesta ok B y D A. "python".sort() B. sorted("python") C. rfind("python","r") D. "python".index("th")
BD is correct
BD is correct
The answer is BD
print ("python".index("t")) 2
sorted_string = sorted("python") print(sorted_string) # Stampa: ['h', 'n', 'o', 'p', 't', 'y']
#"python".sort()#AttributeError: 'str' object has no attribute 'sort' print(sorted("python")) Ans is B,D #rfind("python","r")#NameError: name 'rfind' is not defined "python".index("th") Ans is A,D
#"python".sort()#AttributeError: 'str' object has no attribute 'sort' print(sorted("python")) #rfind("python","r")#NameError: name 'rfind' is not defined "python".index("th") Ans is A,D