ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
s = 'abc' * 2
print(s.count('a'), s.index('c'), s[2::3], len(s.split('b')))- A. 2 5 cc 3
- B. 2 2 c 3
- C. 2 2 cc 2
- D. 2 2 cc 3
Correct answer: D. 2 2 cc 3
abcabc has two a characters, and the first c is at index 2. The slice from index 2 with step 3 takes indices 2 and 5, both c. Splitting on b gives three pieces.
More Python Programming questions
- What is printed? python print(list(map(len, ['ab', 'c', ''])), list(filter(None, [0, 1, '', 'a'])), any([]), all([]))
- What is printed? python print('%d items' % 3, '%s' % 3.0, '%s' % None, '%r' % None)
- What is printed? python print(10 3 == 1000.0, 1e3 == 10 3, type(10 3).name, type(1e3).name)
- What is printed? python print(bin(5), oct(8), hex(16), int('101', 2) + int('7', 8))
- What is printed? python print(sorted(['apple', 'Banana', 'cherry'], key=str.lower), sorted(['apple', 'Banana', 'cherry']))
- What is printed? python print(sum(range(5)) / len(range(5)), sum([1, 2, 3, 4]) // 4, 9 // 2 2 + 9 % 2)