AME 209: 14. Functions and Modularity in Python

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/10

flashcard set

Earn XP

Description and Tags

Vocabulary flashcards for review.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

11 Terms

1
New cards

Built-in Function

Predefined functions provided by Python that perform specific tasks. Examples: input(), print(), len()

2
New cards

User-defined Function

Functions defined by the user using the 'def' keyword, requiring a function name, input(s), and output(s).

3
New cards

Lambda Function

Small, anonymous functions used for short, throwaway functionality, often passed directly to another function; defined using 'lambda arguments: expression'.

4
New cards

Module

A file containing Python code (usually functions or class definitions) that can be reused across scripts to organize code and avoid repetitions.

5
New cards

Custom Module

A .py file containing Python code (functions, constants, or classes) that can be imported into other Python scripts to reuse code and organize projects.

6
New cards

Function Handle

A way to reference a function, allowing it to be passed as an argument to other functions. Supported in MATLAB and can be generated in Python, though not as naturally.

7
New cards

print()

A built-in Python function that prints output to the console.

8
New cards

Anatomy of a built-in function

out1, out2, … = func_name(inp1, inp2, …)

9
New cards

Anatomy of a User-defined Function

def func_name(inp1, inp2, …) :

Function body

return out1, out2, …

10
New cards

Why would you use custom modules?

Custom modules allow for code organization, reuse, and separation of functionality, making programs easier to manage and maintain.

11
New cards

How do you create a custom module?

Write your Python functions and variables in a separate file with a .py extension. Then, you can import this file in your main program using the import statement.