ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
from string import Template
print(Template('$a-$b').substitute(a=1, b=2), Template('$a$c').safe_substitute(a='x'), Template('${a}bc').substitute(a='x'))- A. 1-2 x$c xbc
- B. 1-2 xc xbc
- C. 1-2 x$c x$bc
- D. 12 x$c xbc
Correct answer: A. 1-2 x$c xbc
substitute fills $a and $b, and the braces in ${a} end the name before bc. safe_substitute leaves $c unchanged when no value is given, rather than raising KeyError.
More Python Programming questions
- What is printed? python try: print((300).tobytes(1, 'big')) except OverflowError: print('overflow') print((255).tobytes(1, 'big')…
- What is printed? python print(bool('0'), bool(0.0), bool(-0.0), bool(float('nan')), bool(' '))
- What is printed? python print(True & 2, True | 2, True ^ True, ~True)
- What is printed? python print(-263 // -1 == 263, abs(-263) == 263, (263) (263) > 2127, 263 263 == 2126)
- What is printed? python print(int(1e22) == 1022, int(1e23) == 1023, float(1022) == 1e22)
- What is printed? python print('{:+}'.format(-0.0), '{:+}'.format(0), '{:+.1f}'.format(-0.04), '{:+}'.format(5))