Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.

Unlimited Access

Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.

Exam PCAP topic 1 question 15 discussion

Actual exam question from Python Institute's PCAP
Question #: 15
Topic #: 1
[All PCAP Questions]

Assuming that String is six or more letters long, the following slice
is shorter than the original string by:

  • A. four chars
  • B. three chars
  • C. one char
  • D. two chars
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
Avidulam
Highly Voted 4 years, 1 month ago
Ans is B, three chars less
upvoted 22 times
...
pshdreddy
Highly Voted 3 years, 11 months ago
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' >>>
upvoted 12 times
M7mdAl7aj
3 years, 9 months ago
the result is 4 characters which is 3 characters shorter than the original string.
upvoted 9 times
...
Darkhorse7979
3 years, 8 months ago
The answer always will be 3 characters less as the character at index 0 is excluded and the last 2 characters are excluded
upvoted 11 times
...
...
zantrz
Most Recent 2 months, 1 week ago
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.
upvoted 1 times
...
zantrz
2 months, 1 week ago
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])
upvoted 1 times
...
TheFivePips
4 months, 2 weeks ago
Selected Answer: 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
upvoted 1 times
...
varshu_0708
11 months, 2 weeks ago
the ans is B as the output string is always 3 letters shorter than the original string
upvoted 1 times
...
varshu_0708
11 months, 2 weeks ago
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
upvoted 1 times
TheFivePips
4 months, 2 weeks ago
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.
upvoted 1 times
TheFivePips
4 months, 2 weeks ago
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
upvoted 1 times
...
...
...
naveenbv80
1 year, 4 months ago
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
upvoted 1 times
...
N9
1 year, 7 months ago
a = "abcdef" b = a[1:-2] print(a) print(b) print(len(b)) Output : abcdef bcd 3
upvoted 2 times
...
BenM1911
2 years, 3 months ago
the answer is 3 lst = [1, 2, 3, 4, 5, 6] print(lst[1:-2])
upvoted 2 times
...
AtulVSharma
2 years, 6 months ago
It should return 4 chars
upvoted 1 times
...
Jesuisfort
2 years, 10 months ago
three is correct
upvoted 1 times
...
Jesuisfort
2 years, 11 months ago
the respond is Three
upvoted 2 times
...
ecko
3 years, 7 months ago
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.
upvoted 3 times
FR99
3 years, 5 months ago
Pay attention on the question's wording. It will always be 3 characters shorter regardless the length of the string.
upvoted 4 times
wolverin3
3 years, 5 months ago
Not really, question should mention atleast or regardless but it says original length of string.
upvoted 1 times
wolverin3
3 years, 5 months ago
sorry, I interpreted the question wrongly. No matter the length of string it is 3 characters short of the original string
upvoted 3 times
...
...
...
...
Nehuuu
3 years, 7 months ago
Answer should be B
upvoted 1 times
...
premaseem
3 years, 8 months ago
It would skip the first character and last 2 characters. Answer should be B
upvoted 2 times
...
Saifu
3 years, 11 months ago
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
upvoted 5 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...