Assuming that String is six or more letters long, the following slice
is shorter than the original string by:
Assuming that String is six or more letters long, the following slice
is shorter than the original string by:
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.
Ans is B, three chars less
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' >>>
the result is 4 characters which is 3 characters shorter than the original string.
The answer always will be 3 characters less as the character at index 0 is excluded and the last 2 characters are excluded
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
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.
Pay attention on the question's wording. It will always be 3 characters shorter regardless the length of the string.
Not really, question should mention atleast or regardless but it says original length of string.
sorry, I interpreted the question wrongly. No matter the length of string it is 3 characters short of the original string
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
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.
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
a = "abcdef" b = a[1:-2] print(a) print(b) print(len(b)) Output : abcdef bcd 3
the answer is 3 lst = [1, 2, 3, 4, 5, 6] print(lst[1:-2])
the respond is Three
It would skip the first character and last 2 characters. Answer should be 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.
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])
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]) )
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
the ans is B as the output string is always 3 letters shorter than the original string
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
It should return 4 chars
three is correct
Answer should be B