Sci-fi horror on a Pacific island breaks out in:

Skip to content

Intro to CS | Lecture 7 - Functions

Finally getting functions

Main takeaway:
Functions are reusable mini-programs that take input, do work, and return output. Understanding return vs. print and local vs. global scope makes them much easier to understand.

Programming Using Python – Intro to Computer Science
Date:
April 7, 2026
Topic: Functions

Today I completed the reading and lecture on functions.

Functions used to be one of the parts of programming I did not really understand. Back when I tried to brute-force my way through programming on my own, this was one of the places where I got stuck. Going through the material in order makes it seem much more understandable.

The way I understand a function now is that it is like a small machine inside the program. You define the function, give it a name, and set up parameters that act like placeholders for whatever values you want to pass in. The function then performs some operation on those inputs.

A simple example is checking whether a number is even or odd. A function can take one integer as a parameter, then use an if statement to check whether i % 2 == 0. If that condition is true, the number is even. If false, it is odd.

One of the most important ideas is the difference between return and print.

That distinction helped a lot. A function can be thought of like an expression in math: whatever the function evaluates to gets replaced by its single output.

I also reviewed the idea of scope. A function is kind of like a self-contained room. Inside that room, it can use its own local variables. It may also be able to look outside the room in some cases, but if a variable is created locally inside the function, that variable belongs only to the function. Once the function is done, that local variable is gone, and the rest of the program does not have access to it.

Because of that, I need to be careful about using the same variable names globally and locally. Better practice is to avoid redefining things carelessly and just create a new variable when needed.


Comments

Booker the Capybara

"Hi, I'm Booker! What brings you here today?"

"Awesome. What are you in the mood to read?"

"Great! What process do you want to explore?"

"Let's narrow that down."

"Let's dive into the technical side."

Booker