Set 3 - Functions

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/25

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

26 Terms

1
New cards

function

A reusable block of code that performs a specific task.

2
New cards

def function_name(parameters):

How to define a function.

3
New cards

return

The keyword used to exit a function and send a value back.

4
New cards

parameter

A variable listed inside parentheses in a function definition.

5
New cards

argument

The actual value passed into a function when it's called.

6
New cards

return None

Indicates the function has no explicit return value.

7
New cards

scope of a variable

Local — it exists only inside that function.

8
New cards

mutable arguments

Changes inside the function affect the original object.

9
New cards

immutable arguments

They do not change the original variable.

10
New cards

function call vs definition

A definition creates it; a call executes it.

11
New cards

function call

function_name(arguments)

12
New cards

return multiple values

Return them as a tuple → return a, b, c

13
New cards

capture multiple return values

x, y, z = function()

14
New cards

docstring

To describe what a function does (written as """Description""").

15
New cards

two functions with the same name

The later one overwrites the earlier.

16
New cards

modify a global variable

Only if declared with global var_name.

17
New cards

better practice than modifying globals

Pass values in and return results instead.

18
New cards

top-down design

Breaking a program into smaller, manageable functions.

19
New cards

why use functions

Reusability, readability, debugging simplicity.

20
New cards

printing vs returning

Printing displays output; returning makes data reusable.

21
New cards

default values for parameters

def func(x, y = 10):

22
New cards

call a function without required arguments

It raises a TypeError.

23
New cards

pass expressions as arguments

Yes — they're evaluated before the call.

24
New cards

comment inside functions

Use # for single-line comments.

25
New cards

placeholder function

pass

26
New cards

returning early from a function

Using return inside an if to exit early based on a condition.