PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 15


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

is shorter than the original string by:

Show Answer
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

17 comments
Sign in to comment
AvidulamOption: B
Mar 13, 2020

Ans is B, three chars less

pshdreddyOption: B
May 17, 2020

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
Jun 25, 2020

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

Darkhorse7979
Jul 29, 2020

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
May 24, 2020

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
Sep 20, 2020

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
Nov 1, 2020

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

wolverin3
Nov 17, 2020

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

wolverin3
Nov 22, 2020

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

premaseemOption: B
Aug 8, 2020

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

JesuisfortOption: B
May 2, 2021

the respond is Three

BenM1911Option: B
Dec 29, 2021

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

N9Option: B
Sep 3, 2022

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

varshu_0708Option: B
May 9, 2023

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
Dec 6, 2023

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
Dec 6, 2023

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

NehuuuOption: B
Sep 16, 2020

Answer should be B

JesuisfortOption: B
May 28, 2021

three is correct

AtulVSharmaOption: A
Oct 6, 2021

It should return 4 chars

naveenbv80Option: B
Dec 2, 2022

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

varshu_0708Option: B
May 9, 2023

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

TheFivePipsOption: B
Dec 6, 2023

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

zantrzOption: B
Feb 13, 2024

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
Jun 4, 2024

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

zantrzOption: B
Feb 13, 2024

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.