ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
s = 'abc' print(s.center(7, '*'), s.zfill(5), '-'.join(['x']), s.ljust(2, '.'))
- A. **abc** 00abc x abc
- B. **abc** abc00 x abc
- C. **abc** 00abc x ab.
- D. **abc** 00abc xy abc
Correct answer: A. **abc** 00abc x abc
center(7, '*') pads both sides evenly, with two stars on the left and two on the right. zfill pads with zeros on the left. ljust never shortens a string, so 'abc' stays as it is.
More Python Programming questions
- What is printed? python print(divmod(-9, 4), -9 // 4, -9 % 4, round(-9 / 4))
- What is printed? python d = {'x': 1} e = d d = dict(d) d['x'] = 2 print(e['x'], d['x'])
- What is printed? python nums = [3, 3, 1] print(nums.index(3), nums.count(3), [i for i, v in enumerate(nums) if v == 3])
- What is printed? python print(int('0b1011', 2), int('0b1011', 0), int('z', 36), int('1011', 2))
- What is printed? python h = 0 for ch in 'abc': h = (h 31 + ord(ch)) % 1000 print(h, (-7) % 1000, (-7 31) % 1000)
- What is printed? python print(sorted(['b2', 'a10', 'a9', 'b1'], key=lambda s: (s[0], int(s[1:]))), sorted(['b2', 'a10', 'a9', 'b1']))