ProgrammingModerateTCS NQT · Accenture
What is printed?
What is printed?
s = 'hello'
try:
s[0] = 'j'
except TypeError:
print('immutable')
t = s.replace('h', 'j')
print(t, s)- A. immutable | jello hello
- B. jello hello
- C. immutable | hello hello
- D. TypeError | jello hello
Correct answer: A. immutable | jello hello
Strings cannot be changed in place, so item assignment raises TypeError. replace returns a new string and leaves s unchanged.
More Python Programming questions
- What is printed? python print(1020 / 1019, 1020 // 1019, 264 % 1000, 1020 == 1e20)
- What is printed? python calls = [] def f(x): calls.append(x) return x 2 m = map(f, [1, 2, 3]) print(calls) first = next(m) print(calls…
- In Python, when is the outermost iterable of a generator expression such as (x for x in make()) evaluated?
- What is printed? python class Countdown: def init(self, n): self.n = n def iter(self): while self.n > 0: yield self.n self.n -= 2 c =…
- What is printed? python from itertools import permutations p = sorted(permutations('cab')) print([''.join(x) for x in p][3], len(p))
- What is printed? python print(() is (), [] is [], (1, 2) == (1, 2))