MD2 Introduction to functions: Introduction to functions Flashcards

1
Q

Functions

A

As the complexity of our programs grow, it’s also likely that we’ll reuse the same lines of code. Writing this code multiple times would be time-consuming, but luckily we have a way to manage this. We can use functions.

A function is a section of code that can be reused in a program.

As far as functions, we can think about them like a dishwasher. If you aren’t using a dishwasher, you’ll spend a lot of time washing each dish separately. But a dishwasher automates this and lets you wash everything at once. Similarly, functions improve efficiency. They perform repetitive activities within a program and allow it to work effectively. Functions are made to be reused in our programs. They consist of small instructions and can be called upon any number of times and from anywhere in our programs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Benefit to Functions

A

Another benefit to functions is that if we ever had to make changes to them, we can make those changes directly in the function, and there’ll be applied everywhere we use them. This is much better than making the same changes in many different places within a program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Built in Functions

A

The print() function is an example of a built-in function. Built-in functions are functions that exist within Python and can be called directly. They are available to us by default. We can also create our own functions. User-defined functions are functions that programmers design for their specific needs.

Both types of functions are like mini-programs within a larger program. They make working in Python much more effective and efficient. Let’s continue learning more about them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly