What is the output of print(sum(1 for c in 'banana' if c == 'n')) in Python?
print(sum(1 for c in 'banana' if c == 'n'))
Correct answer
C. 2
5 views
C. 2
5 views
Counting items with a generator expression inside sum().
Asked in: Python Interview Advanced
https://docs.python.org/3/library/index.htmlNot sure why the answer is C? Ask here and get an explanation.