ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
s = 'aAbBcC'
print(s.lower().count('a') + s.upper().count('A'), s.swapcase(), ''.join(c for c in s if c.islower()))- A. 2 AaBbCc abc
- B. 4 AaBbCc abc
- C. 4 aAbBcD abc
- D. 4 AaBbCc abd
Correct answer: B. 4 AaBbCc abc
After lower() the string has two a's, and after upper() it has two A's, giving 4. swapcase flips every letter's case, and the generator keeps only the lowercase letters.
More Python Programming questions
- What is printed? python s = '2024-06-01' y, m, d = map(int, s.split('-')) print(y + m + d, s.replace('-', '/'), '%02d/%02d/%04d' % (d, m…
- What is printed? python print('%d' % 1020, '%.3e' % (270), len('%d' % (2100)), '%x' % (270))
- What is printed? python print(int(float('9007199254740993')) == 9007199254740993, float('9007199254740993') == 9007199254740992.0…
- What is printed? python nums = [3, 1, 4, 1, 5, 9, 2, 6] print(sorted(nums)[len(nums) // 2], sorted(nums)[(len(nums) - 1) // 2], sum(nums)…
- What is printed? python print(sum([0.1] 3) == 0.3, sum([0.1] 3, 0.0) == 0.30000000000000004, sum([1e100, 1.0, -1e100]))
- What is printed? python print(-(2 3) 2, (-2) 3 2, -2 -1, 0)