PCAP Exam QuestionsBrowse all questions from this exam

PCAP 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]

Show Answer
Correct Answer: BD

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

6 comments
Sign in to comment
deckmanOptions: BD
May 14, 2022

B and D are correct

macxszOptions: BD
Apr 30, 2022

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

Jos015Options: BD
Nov 8, 2023

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)

dicksonpwcOptions: BD
Mar 13, 2023

B and D are correct answer

dicksonpwcOptions: BD
Apr 25, 2023

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

emanuelcar990Options: BD
Aug 17, 2023

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