Exam PCAP All QuestionsBrowse all questions from this exam
Question 86

Which of the following invocations are valid? (Choose two.)

    Correct Answer: B, D

    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.

Discussion
andr3

hey admin, can you correct those signs to correct signs ?

vlobachevskyOptions: BD

BD is correct

macxszOptions: BD

B. sorted("python") D. "python".index("th")

stuartzOptions: BD

>>> sorted("python") ['h', 'n', 'o', 'p', 't', 'y'] >>> "python".index("th") 2

zantrzOptions: BD

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.

dcrossOptions: BD

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")

JnanadaOptions: BD

BD is correct

Noarmy315Options: BD

BD is correct

DTL001Options: BD

The answer is BD

Damon54

print ("python".index("t")) 2

Damon54

sorted_string = sorted("python") print(sorted_string) # Stampa: ['h', 'n', 'o', 'p', 't', 'y']

seaverickOptions: BD

#"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

seaverickOptions: AD

#"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