ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
print(','.join(['a', 'b']), ','.join('ab'), '%s' % ['a', 'b'], str(('a',)))- A. a,b a,b a,b ('a', 'b')
- B. a,b a,b ['a', 'b'] ('a',)
- C. a,b a,b ['a', 'c'] ('a',)
- D. a,b a,b ('a', 'd') ('a',)
Correct answer: B. a,b a,b ['a', 'b'] ('a',)
Joining a string iterates over its characters, so ','.join('ab') is also 'a,b'. %s uses str() on the list, which shows brackets, and the one-item tuple keeps its trailing comma.
More Python Programming questions
- What is printed? python import math print(math.prod([2, 3, 4]), math.prod([]), math.prod([1.5, 2]), math.prod(range(1, 6)) ==…
- What is printed? python words = ['bb', 'a', 'ccc'] print(max(words), max(words, key=len), min(words, key=len), sorted(words, key=lambda w…
- What is printed? python print(len(f'{1234.5:.0f}'), f'{1234.5:.0f}', f'{1235.5:.0f}', f'{-1234.5:.0f}')
- What is printed? python print(1e3 == 103, int(1e3) is not None, 1e3 // 1 == 103, type(1e3 // 1).name)
- What is printed? python print('%x' % -255, '%o' % 8, '%e' % 0.0, '%.0e' % 12345)
- What is printed? python print(5 & 6 | 1, 5 & (6 | 1), 5 ^ 6 & 1, 1 | 2 ^ 3 & 4)