Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
Recall basic information about Python functions.
Prerequisites
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
[MUSIC]
0:00
Hey, my name is Ashley Boucher and
in this course,
0:09
we're gonna be diving
deeper into functions.
0:12
You might have touched on functions
previously in your coursework, but
0:14
before moving on, be sure to check
the teacher's notes to make sure you've
0:17
covered all the prerequisites for
this course.
0:21
Also, don't forget that you have complete
control over how you watch this video.
0:23
Want to slow me down or speed me up?
0:26
Go for it, feel free to pause, rewind,
or even fast-forward as necessary.
0:28
So what's a function?
0:32
A function is
a reusable block of code.
0:34
You write a block of code,
give it a name, and
0:36
then you can call the block of
code whenever you need to use it.
0:39
Typically, a function does one programming
task and it does it really well.
0:42
That's the standard we're looking for,
in other words,
0:46
you should be able to think of a short and
descriptive name for your function.
0:49
If you can't do that,
the function is probably doing too much.
0:52
One thing developers should always
try to do is not repeat themselves.
0:56
This is known as DRY programming or
Don't Repeat Yourself.
0:59
Functions are great way to help us
avoid writing the same code over and
1:03
over because we can just call the function
whenever we need to execute that code.
1:06
Another equally important
reason to use functions is
1:11
that they make your code easy to read and
follow, they also make easy to test.
1:13
Sure, you could write your code for
1:17
program in one script file without any
functions, but what if there's a bug?
1:19
How would you ever find it let alone
squash it, and how would anyone also
1:23
working on your code
know what it was doing or
1:27
make changes to it without
breaking something?
1:30
Functions are everywhere in programming
and they are very important, so
1:32
let's learn more about them.
1:35
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up