PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 86


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

Show Answer
Correct Answer: BD

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

13 comments
Sign in to comment
andr3
Mar 19, 2023

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

vlobachevskyOptions: BD
Oct 11, 2021

BD is correct

macxszOptions: BD
May 4, 2022

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

stuartzOptions: BD
Jun 15, 2022

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

DTL001Options: BD
Dec 19, 2021

The answer is BD

Noarmy315Options: BD
Jan 16, 2022

BD is correct

JnanadaOptions: BD
Aug 18, 2022

BD is correct

dcrossOptions: BD
Nov 15, 2023

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

zantrzOptions: BD
Feb 1, 2024

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.

seaverickOptions: AD
Jan 27, 2024

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

seaverickOptions: BD
Jan 27, 2024

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

Damon54
Feb 6, 2024

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

Damon54
Feb 6, 2024

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