ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
s = 'hello world' print(s.capitalize(), s.title().swapcase(), s.center(15, '*'), s.zfill(13))
- A. Hello world Hello Word **hello world** 00hello world
- B. Hello world hELLO wORLD **hello world** 00hello world
- C. Hello world hELLO wORLD *hello world* 0hello world
- D. Hello World hELLO wORLD **hello world** 00hello word
Correct answer: B. Hello world hELLO wORLD **hello world** 00hello world
capitalize uppercases only the first letter, and title followed by swapcase gives hELLO wORLD. center pads the 11-character text to 15 with two stars on each side, and zfill pads with zeros on the left, even before letters.
More Python Programming questions
- What is printed? python print(divmod(-7, 2), divmod(7, -2.0), 7 // -2.0, -7 % 2.5)
- What is printed? python x = -17 print(x // 5, x % 5, divmod(x, -5), x.mod(5))
- What is printed? python print(1018 + 1 == 1000000000000000001, 231 - 1 + 1, -(231), (231) (231) == 262)
- What is printed? python s = 'a' for i in range(3): s = s + s[::-1] + str(i) print(s, len(s))
- What is printed? python t = (1, 2, 3) t += (4,) u = t t = 2 print(t, u, t is u, len(t) len(u))
- What is printed? python lst = [1, 2, 3] lst2 = lst lst = 2 lst2 += [9] print(lst, lst2, lst is lst2)