ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
b = b"abc" print(b[0], b[:1], list(b"hi"), bytes([65, 66]), b"a" + bytearray(b"b"))
- A. b'a' b'a' ['h', 'i'] b'AB' b'ab'
- B. 97 b'a' [104, 105] b'65 66' b'ab'
- C. 97 b'a' [104, 105] b'AB' b'ab'
- D. 97 97 [104, 105] b'AB' bytearray(b'ab')
Correct answer: C. 97 b'a' [104, 105] b'AB' b'ab'
Indexing bytes gives an int, slicing gives bytes. Iterating bytes yields ints. bytes([65, 66]) builds from code values. bytes + bytearray returns the type of the left operand, bytes.
More Python Programming questions
- What is printed? python print(chr(ord("a") + 25), ord("A") - ord("a"), "".join(chr(ord(c) ^ 32) for c in "PyThOn"), str(b"x", "ascii"))
- What is printed? python print(min([], default=0), max([2, 7], default=0), min("b", "a", key=ord), sum([[1], [2]], []))
- What is printed? python for kw in [{}, {"strict": True}]: try: print(list(zip("ab", [1, 2, 3], kw)), end=" ") except ValueError…
- What is printed? python def g(): yield from range(2) yield from "ab" return "done" def h(): r = yield from g() yield r print(list(h())…
- What is printed? python def evens(): n = 0 while True: yield n n += 2 def take(k, it): return [next(it) for in range(k)] e = evens()…
- What is printed? python def pipeline(): nums = (n for n in range(10)) sq = (n n for n in nums if n % 2) big = (s for s in sq if s > 10)…