Embercode
✕
Functions and ScopeQuick quiz

Static methods and lambdas in Python

8 questions. Covers Lambdas in Python.

Questions 1 to 5 of 8

  1. 1. What does this program print? ``python def count_vowels(text): return sum(1 for ch in text.lower() if ch in "aeiou") def clamp(value, low, high): return max(low, min(value, high)) print(count_vowels("Programming"), clamp(-3, 0, 10)) ``
  2. 2. What does this program print? ``python words = ["kiwi", "fig", "apple", "pear"] words.sort(key=lambda w: len(w)) print(words) ``
  3. 3. A class Cart stores a list of prices and has the method def total(self), which returns their sum. Which call works from outside the class?
  4. 4. What does this program print? ``python n = 1 show = lambda: print("n inside =", n) n = 2 show() ``
  5. 5. What happens when Python reads this line? ``python f = lambda x: y = x + 1 ``

5 question(s) left on this page.