Python for Absolute Beginners Transcripts
Chapter: Course conclusion
Lecture: Review: Functions

Login or purchase this course to watch this video and the rest of the course contents.
0:00 One of the most powerful tools we have in our programming toolbox for changing the way that we think about and work with our code is functions.
0:09 Functions allow us to group together a bunch of small little steps into one very simple step. Here we have a bunch of things going on
0:16 we have a function called play around. It takes some arguments and then we take a bunch of work inside the function.
0:21 But all that matters once we write this when we want to use it we know pass player_1 and player_2's name and then what we'll get back
0:29 is the value of the winner. Either player_1 or player_2 or if there's a tie, we get none. And that allows us two really important things.
0:38 One, it allows up to think about well this step is where you play the round. We don't have to worry about the details.
0:43 Remember in our later part of the course we changed the way that we got the input from the users. We got that instead of just saying
0:51 input and type in a number we actually used that autocomplete thing. The stuff that was calling get play or get role from the user
0:58 they didn't have to go and know that we changed how that worked. It just got changed and everywhere we used it automatically
1:04 the better version got used. It allows us to hide away and not worry about the details just used the high level idea of playing around.
1:10 It also lets us organize our code in a way that is much simpler. We can think about here we're going to play around
1:16 we're going to check for the winner. If there's enough winners. I have enough wins for any given player we're going to exit out of the loop
1:22 and they win. It allows you to think at a very high level instead of at every single bit you're thinking about the details. Super cool.
1:29 Be sure to make use of functions try to keep them short and small. If they get really long and cumbersome you probably want to break that further
1:36 into smaller functions. Allow you to get smaller and smaller detail as you go down and not get things too complicated all in one place.

Talk Python's Mastodon Michael Kennedy's Mastodon