ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print('a'.join('xyz'), 'xyz'.join(['a']), 'ab'.join(['', '']), ','.join(map(str, [1.0, 2])))- A. xayaz a ab 1.0,2
- B. xyzaxyz a ab 1.0,2
- C. xayaz a ba 1.0,2
- D. xayaz a ab 1,2
Correct answer: A. xayaz a ab 1.0,2
join puts the separator between items, so 'a'.join('xyz') is xayaz. A single item has no separators, and joining two empty strings gives only the separator. str(1.0) is '1.0', not 1.
More Python Programming questions
- What is printed? python print(round(0.5 3), round(4.5) + round(5.5), int(2.9999999999999996), int(3.0000000000000004))
- What is printed? python print('Python' 0 + 'x', 'Py' + 'thon' 0, len('' 100))
- What is printed? python print(len(str(2100)), str(2100)[-3:], (2100) % 1000)
- What is printed? python x = 5 x += 2 x print(x, x - 2 3 2 // 9 1, x // 4 4 + x % 4)
- What is printed? python print([i for i in range(10) if i % 3 == 0][::-1], [i i for i in range(5)][-2:], len([]) == 0)
- What is printed? python print('%.2f' % 1.255, '%.2f' % 1.245, '%.1f' % 0.05, '%.1f' % 0.15)