The "pass" Statement
In some situations you may want to write the rough structure for a program without implementing certain parts of it.
This is where the pass
statement comes into play.
This lesson explains where and when you need the pass
statement and how you can use it to enhance your development flow.
00:00
The pass
Statement. In the next slide, I’m going to show you what the pass
statement does. Nothing! Isn’t it beautiful? You’ll use the pass
statement as a placeholder.
00:13 You’ll hear it called a code stub. This is typically used when you’re building something out and maybe you’re on a roll and you just kind of want to put the rough outline out there of your code and you’re going to come back to it later.
00:26
The pass
statement is great for doing this. So, why don’t we jump into the console for an example? Let’s jump into the code that you wrote for video two, the calorie counter app. Let’s say you slept on it, you had a great idea, and you want to take this app to the next level but you want to make some changes. Give this a try on your own.
00:47 So, if I delete this line
00:51
and try to run this program, I should get an error. Yeah, see? We got a IndentationError: expected an indented block
. Now, if I come back in, indent, and give this the pass
statement,
01:10
it won’t do anything, but it’ll run just fine. There you go! Now you’re free to make all the changes to your heart’s content without throwing errors! That concludes the pass
statement. See you in the next one.
Become a Member to join the conversation.
Ben Nduwuba on July 15, 2020
Very clear and easy to follow course. Thanks Paul !