โ† All POC Flashcard Decks

Core Python Programming Concepts Flashcards

7 cards from real POC practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 7 Core Python Programming Concepts flashcards as text
  1. Which of the following correctly defines a class method in Python?

    Answer: Using the @classmethod decorator with cls as first parameter

    A class method is defined with `@classmethod` and receives the class itself (conventionally named `cls`) as its first argument.

  2. What is the output of `'abc' * 3`?

    Answer: 'abcabcabc'

    String repetition with `*` concatenates the string the specified number of times, producing 'abcabcabc'.

  3. What does `dict.get(key, default)` return when the key is absent?

    Answer: Returns the default value

    `dict.get(key, default)` returns the default value you specify if the key is not found, avoiding a KeyError.

  4. Which Python keyword is used to define an anonymous function?

    Answer: lambda

    The `lambda` keyword creates a small anonymous function that can have any number of arguments but only one expression.

  5. What is the purpose of the `nonlocal` keyword?

    Answer: It allows an inner function to modify a variable in an enclosing (non-global) scope

    `nonlocal` lets a nested function read and write a variable defined in the nearest enclosing function scope that isn't global.

  6. What is the result of `set([1, 2, 2, 3, 3, 3])`?

    Answer: {1, 2, 3}

    Converting a list to a set removes all duplicate values, leaving only unique elements.

  7. Which statement about Python decorators is true?

    Answer: A decorator is a function that takes a function and returns a modified function

    A decorator is a higher-order function that wraps another function, extending or altering its behavior without modifying its source.