ProgrammingEasyTCS NQT · Infosys pattern
What is printed?
What is printed?
print("abc" * 2 + "d", len("abc" * 0))- A. abcdabcd 0
- B. abcabcd 3
- C. abcabcd 0
- D. abcabcd ''
Correct answer: C. abcabcd 0
* binds tighter than +, so "abc" * 2 + "d" is "abcabc" + "d" = "abcabcd". Repeating a string 0 times gives the empty string, whose length is 0. "abcdabcd" wrongly applies + first.
More Python Programming questions
- What is printed? python x = [10, 20, 30, 40, 50] print(x[-1], x[len(x) // 2], x[-2:])
- What is printed? python s = "Python" print(s.find("th"), s.find("z"), s.upper()[1:3])
- What is printed? python s = "a-b-c-d" print(s.split("-", 2), s.rsplit("-", 1))
- What is printed? python print("hello world".title(), "ab".center(6, ""), "42".zfill(5), "-7".zfill(4))
- What is printed? python d = dict(zip("abc", range(3))) d.update({"b": 9, "d": 1}) print(list(d.items())[1], sum(d.values()), len(d))
- What is printed? python a = {1, 2, 3, 4} b = {3, 4, 5} print(a - b, b - a, len(a | b), a & b == {4, 3})