Exam PCAP All QuestionsBrowse all questions from this exam
Question 140

Assuming that the snippet below has been executed successfully, which of the following expressions evaluate to True? (Choose two.) string = 'SKY'[::-1] string = string[-1]

    Correct Answer: B, D

    After reversing the string 'SKY', the result is 'YKS'. Then assigning string = string[-1] sets string to 'S'. Thus, string[0] refers to 'S', and since string has only one character, string[-1] also refers to 'S', making string[0] == string[-1] true. The length of the string 'S' is 1, making len(string) == 1 true.

Discussion
deckmanOptions: BD

B and D are correct

Jos015Options: BD

string = 'SKY'[::-1] print (string) string = string[-1] print (string) print (string[0] == 'Y') print (string[0] == string[-1]) print (string is None) print (len(string) == 1)

macxszOptions: BD

True: B. string[0] == string [-1] D. len(string) == 1

emanuelcar990Options: BD

string after reverse and just take -1 = string = S string[0] == string [-1] len(string) == 1

dicksonpwcOptions: BD

Ans A, False # string[0] == 'S' =>So string[0] !== 'Y' return false Ans B, False # string[0] == 'Y' => but string[-1] = S, return false Ans C, False # string is None => but string = 'SKY', so return false Ans D, True # len(string) = 1 => so len(string) == 1, so return true Correct answer should be B and D

dicksonpwcOptions: BD

B and D are correct answer