ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
s = "a b\tc\n"
print(s.split(), len(s.split(" ")), len(s.strip(" ")), len(s.strip()))- A. ['a', 'b', 'c'] 2 7 6
- B. ['a', 'b', 'c'] 3 5 4
- C. ['a', 'b', 'c'] 3 7 6
- D. ['a', 'b\tc'] 3 7 6
Correct answer: C. ['a', 'b', 'c'] 3 7 6
split() with no argument splits on runs of any whitespace. split(' ') splits on each single space, giving 3 pieces with an empty string between the two spaces. strip(' ') removes only spaces (none at the ends, so length 7), while strip() also removes the trailing newline (length 6).
More Python Programming questions
- What is printed? python print("ß".upper(), "ß".casefold() == "SS".casefold(), "fi".upper(), len("ß".upper()))
- What is printed? python print("abc" -1 == "", [0] 0, "b" in "abc", "" in "abc", "abc".find(""), "abc".count(""))
- What is printed? python print("%s|%r|%.3s|%5.2e|%o" % ("a", 1.0, "python", 1234.5, 8))
- What is printed? python w = 7 print(f"{'x':>{w}}|{3.0:g}|{1e-5:.0e}|{0.5:.0%}|{-3:+d}|{12:08b}")
- What is printed? python print(int(True), int("0b101", 0), int("0o17", 0), int("ff", 16), int(" 12n"), int(" 0x10 ", 16))
- What is printed? python from fractions import Fraction as F from decimal import Decimal as D print(F(1, 3) + F(1, 6), D("0.1") + D("0.2")…