QuestionQ122

Miscellaneous (List Comprehensions, Lambdas, Closures, I/O)

Which of the following invocations are valid?

Choose two
  • A "python".index("th")
  • B rfind("python","r")
  • C "python".sort()
  • D sorted("python")
Explanation

str.index() is a valid method for finding a substring within a string. sorted() accepts a string as an iterable and returns a list containing its characters in sorted order. rfind is not a standalone built-in function, and strings do not provide a sort() method.

Community Discussion

No comments yet. Be the first to start the discussion!