ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print('Hello World'.swapcase().title(), 'tEST'.capitalize(), 'x'.isalpha(), '1.5'.isdigit(), '١٢'.isdigit())- A. Hello World Test False False True
- B. Hello World Test True False True
- C. Hello World Test True True True
- D. Hello World Text True False True
Correct answer: B. Hello World Test True False True
swapcase then title restores the capitals, and capitalize lowercases the rest. isdigit accepts Unicode digits such as Arabic-Indic ones, but fails on the dot in '1.5'.
More Python Programming questions
- What is printed? python print('ab' in 'cabd', '' in 'abc', 'abc'.index(''), len('abc'[3:]), len('abc'[4:]))
- What is printed? python print(sum(map(int, str(220))), len(str(350)), str(105)[::-1].count('0'))
- What is printed? python print(float('0.1') + float('0.2') == float('0.30000000000000004'), 0.1 + 0.2 == 0.30000000000000004)
- What is printed? python print(5 // 0.4, 5 % 0.4, 0.4 12 == 4.8, 5 / 0.4)
- What is the time complexity of s[::-1] for a string of length n in CPython?
- Which call builds one string from n pieces in O(total length) time?