Programming with Python - Functions

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/32

flashcard set

Earn XP

Description and Tags

Chapter 6 - Functions

Last updated 4:06 PM on 8/17/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

33 Terms

1
New cards

What is a function in Python?

A named block of code that performs a task; created with def, called with name().

2
New cards

Why use functions?

Reduce repetition, improve readability, keep code organized.

3
New cards

What does return do?

Sends one value back to the caller and ends the function.

4
New cards

What happens if a function has no return?

It returns None.

5
New cards

What is a parameter?

Variable in the function definition.

6
New cards

What is an argument?

The value provided during the call.

7
New cards

How do multiple parameters work?

Arguments match parameters by position unless using keyword arguments.

8
New cards

What is a nested function call?

A function used inside another function call.
Example: int(input())

9
New cards

What is a void function?

A function that prints but does not return anything (None).

10
New cards

What is polymorphism in Python?

Operators behave differently depending on argument types.
Examples:
5 + 5 → 10
"a" + "b" → "ab"

11
New cards

What is dynamic typing?

Variable types are determined at runtime and can change.

12
New cards

What benefits do functions offer?

  • Readability

  • Modular development

  • Avoiding redundant code

  • Easy testing

  • Smaller, focused tasks

13
New cards

What is a function stub?

Placeholder used before writing full code.
Examples:
pass or print("Not implemented").

14
New cards

Are functions objects?

Yes. They can be assigned to variables or passed as arguments.

15
New cards

What operation do functions support?

The call operation: func().

16
New cards

Common function mistakes?

  • Copy-paste errors

  • Returning the wrong variable

  • Forgetting a return (causes None)

17
New cards

What is local scope?

Variables created inside a function; disappear when function ends.

18
New cards

What is global scope?

Variables defined outside functions.

19
New cards

How to modify a global inside a function?

Use global varname.

20
New cards

How does Python find a variable name?

  1. Local

  2. Global

  3. Built-in
    (if not found → NameError)

21
New cards

How does Python pass arguments?

Pass-by-assignment (object reference).

22
New cards

What happens to immutable objects (int, str)?

"Changes" inside the function do not affect the original.

23
New cards

What about mutable objects (list, dict)?

Changes inside the function affect the original.

24
New cards

What are keyword arguments?

Calling parameters using their names: func(x=3, y=5).

25
New cards

What is a default parameter?

A parameter with a preset value if not provided.

26
New cards

What is the danger with mutable default args?

Same list/dict is reused across calls.

Correct pattern:

def func(a=None):
    if a is None:
        a = []

27
New cards

What does *args collect?

Extra positional arguments → tuple.

28
New cards

What does **kwargs collect?

Extra keyword arguments → dictionary.

29
New cards

Ordering rule of arbitrary arguments?

normal → *args**kwargs

30
New cards

How to return multiple values?

Return a tuple: return a, b

31
New cards

What is unpacking?

Assigning tuple elements to variables:
x, y = func()

32
New cards

What is a docstring?

Triple-quoted description inside a function.

33
New cards

Purpose of docstrings?

Document behavior and be readable via help().