ProgrammingModerateGATE CS · Product-company placement
What is printed?
What is printed?
s = "a,b,,c,"
print(len(s.split(",")), len(s.split()), s.rsplit(",", 2)[0], s.partition(";")[0] == s)- A. 3 1 a,b, True
- B. 5 1 a True
- C. 5 1 a,b, False
- D. 5 1 a,b, True
Correct answer: D. 5 1 a,b, True
split(',') keeps empty strings, giving ['a', 'b', '', 'c', ''] (5 items); split() with no separator finds no whitespace, so one item. rsplit with maxsplit 2 splits only the last two commas. partition with an absent separator returns (s, '', '').
More Python Programming questions
- What is printed? python s = "a btcn" print(s.split(), len(s.split(" ")), len(s.strip(" ")), len(s.strip()))
- 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))