ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print([int(t, 0) for t in " 12_000 \t-0b101 +7 ".split()])
- A. [12000, -5, 7]
- B. [12000, -101, 7]
- C. [12, -5, 7]
- D. ValueError
Correct answer: A. [12000, -5, 7]
split() with no argument breaks on any run of whitespace. int(s, 0) picks the base from the prefix (0b means binary), allows a sign and allows underscores between digits, so -0b101 is -5 and 12_000 is 12000.
More Python Programming questions
- What is printed? python import sys print(sys.getintmaxstrdigits()) try: s = str(10 4300) except ValueError: print("too long")
- What is printed? python print(len(str(2 1000 5 1000)))
- What is printed? python rows = [(2, 'b'), (1, 'z'), (2, 'a'), (1, 'y')] print(sorted(rows, key=lambda t: (-t[0], t[1])))
- What is printed? python print(sorted(['bb', 'a', 'cc', 'd', 'ee'], key=len, reverse=True))
- What is printed? python import bisect a = [1, 2, 2, 2, 3] print(bisect.bisectleft(a, 2), bisect.bisectright(a, 2), bisect.bisectright(a…
- What is printed? python import bisect print(bisect.bisectleft([5, 4, 3], 4))