Exam PCAP All QuestionsBrowse all questions from this exam
Question 15

Assuming that String is six or more letters long, the following slice

is shorter than the original string by:

    Correct Answer: B

    Given the slice string[1:-2], the substring excludes the first character (index 0) and the last two characters. This means it includes characters from index 1 to len(string)-3. Therefore, for a string of at least six characters, the sliced string would always be shorter by three characters compared to the original string.

Discussion
AvidulamOption: B

Ans is B, three chars less

pshdreddyOption: B

Question was 6 or more.if he consider 7 word string then ans was A.if he consider 6 words string then answer was B >>> str = 'examtop' >>> str[1:-2] 'xamt' >>>

M7mdAl7aj

the result is 4 characters which is 3 characters shorter than the original string.

Darkhorse7979

The answer always will be 3 characters less as the character at index 0 is excluded and the last 2 characters are excluded

SaifuOption: B

Answer is always B, three chars less. Last 2 characters are dropped by the -2 and the starting index is 1 instead of 0, so first character is dropped

ecko

There is not a right answer on here because it really depends on how long the string is. If it has six letters then print will produce three of those letters. It'll increase depending on how many letters are in the string.

FR99

Pay attention on the question's wording. It will always be 3 characters shorter regardless the length of the string.

wolverin3

Not really, question should mention atleast or regardless but it says original length of string.

wolverin3

sorry, I interpreted the question wrongly. No matter the length of string it is 3 characters short of the original string

varshu_0708Option: B

if the string has 6 letters, the ans is B, if we keep on increasing the length of string, the output string length will also increase. for example: >>> str = '1234567' >>> str[1:-2] 2345 >>> str = '12345678' >>> str[1:-2] 23456 input 7 letter string--output 4 letter input 8 letter string--output 5 letter

TheFivePips

the -2 portion of the slice means that the sliced string will always proportionally increase in size as well compared to the original string. It only ever slices up to the last 2 characters in the string.

TheFivePips

the question is asking for the difference in length between the original string and the sliced string. So you have to subtract the length of the slice from the original. Youll find its 3 every time

N9Option: B

a = "abcdef" b = a[1:-2] print(a) print(b) print(len(b)) Output : abcdef bcd 3

BenM1911Option: B

the answer is 3 lst = [1, 2, 3, 4, 5, 6] print(lst[1:-2])

JesuisfortOption: B

the respond is Three

premaseemOption: B

It would skip the first character and last 2 characters. Answer should be B

zantrzOption: B

print(string[1:-2]): Print the slice of string from index 1 (inclusive) to the second-to-last index (exclusive). The slice includes characters from index 1 to index -3.

zantrzOption: B

B. 3. Analyze these three cases and it will be easily visible that it always 3: string="ABCDEFGHIJ" print(string[1:-2]) string="ABCDEFGHI" print(string[1:-2]) string="ABCDEFG" print(string[1:-2])

vale_76_na_xxx

I don't think so : string="ABCDEFGHIJ" print(len(string[1:-2]) ) = 7 string="ABCDEFGHI" = 6 print(len(string[1:-2])) = 4 string="ABCDEFG" print(len(string[1:-2]) )

TheFivePipsOption: B

6 length example: "string" Slicing the string from index 1 to -2 ("tri"): Original length: 6 Sliced length: 3 Difference: 6 - 3 = 3 chars 7 length example: "stringg" Slicing the string from index 1 to -2 ("trin"): Original length: 7 Sliced length: 4 Difference: 7 - 4 = 3 chars

varshu_0708Option: B

the ans is B as the output string is always 3 letters shorter than the original string

naveenbv80Option: B

If the word has 6 letters, for example str='naveen' print(str[1:-2]) The answer is B, which is 3 chars If the word has 7 letters then the answer is 4 chars str1='Atharva' print(str1[1:-2]) The answer is A, it has 4 chars

AtulVSharmaOption: A

It should return 4 chars

JesuisfortOption: B

three is correct

NehuuuOption: B

Answer should be B