Latest Posts
Python Institute PCAP – Functions and Variable Scope Part 2
Scope and Nested Functions And we’re going to explore further the concept of scope and variable scope and how that changes. So you’ve seen how to define methods before, right? We’ve got this increase age method and then you see that there’s this nesting going on here. Four spaces, or a tab basically means that whatever is inside of the body of this method needs to be four spaces in. So I can do stuff in this method, you know, I could do all types of instructions, write comments and…
Python Institute PCAP – Functions and Variable Scope
Introduction to Creating Functions Functions to perform various things so far in this course. And I told you that we’ll get into the hood, under the hood details later about what a function is and how you can create one. Because I’m of the view that you should learn how to drive a car first before trying to understand how the engine works. And so that’s what we’ve been doing. We’ve been driving the car when it comes to functions. And now to understand functions at a better level and…
Python Institute PCAP – Control Flow Part 6
Section 4 Assignments: Part 2 Assignment number four. Given a non-empty string like code, return a string like CCO C-O-D-C-O-D-E. So it’s basically spelling this out one letter at a time. It’s basically doubling up. So, for example, in this second case, ABC, it has a first, right? And then it has a B, and then it has ABC for AB. If we were to pass this as an argument, it would take A, and then it would do AB. All right, so this method is called grow string. And…
Python Institute PCAP – Control Flow Part 5
Accepting Input From a User Have something run and print things to the screen or anything. So I’m sure you’re dying to make your programs more interactive. And don’t worry, we’re going to get into all of that much later. But for now, I just want to introduce the ability for you to prompt a user to type something and then you can use that text or whatever they typed in your program. And so the way to do that, to accept user input, and there’s many ways of accepting…
Python Institute PCAP – Control Flow Part 4
Range, Enumerate, and Zip Functions Functions. Let’s say that you have a word, for example, let’s just create a variable called word and we’ll say that the word says hello. Okay, if I wanted to take each of these characters and dump them into a list, one way of doing that is actually loop through this list and take those and assign each of these characters, append them to a list object. As we’ve you’ve seen earlier, there’s an append method that you can invoke on a list that’s one…
Python Institute PCAP – Control Flow Part 3
While Loops Now we’re going to talk about the while loop, okay? And this is actually very simple. It basically does exactly what it sounds like. While something is true, do something. So the general syntax is While something is true. So you have a condition here. I’m not going to write any Python code just yet. I’m just going to write some pseudo code, really? While some condition is true, and we talked about conditions with AFL statements and so on, then we’re going to do something else. Do…
Python Institute PCAP – Control Flow Part 2
For Loops And that’s essentially being able to skip lines. If you don’t want a certain line of code to run based on some logic or some condition being met, then you use the if else statements. If this, then do this, otherwise do that. That’s a way of controlling the flow of the program. Now there’s another way of controlling the flow of the program. And this is very important, just like the lectures before. And this has to do with iteration, meaning doing something over and over again….
Python Institute PCAP – File IO and Exception Handling in Python Part 4
argv Command Line Arguments and the re Module To do with scripting. So we talked about how we can run a Python program from the command line from a terminal window, right? We did that earlier in the course. So we’re going to be building a utility where we can actually have a Python file and we can use it to do something, something useful, okay? And it’ll have to do with doing things in the directories. And you’re going to get practice working with the OS s Walk method…
Python Institute PCAP – File IO and Exception Handling in Python Part 3
Traversing Directories Using the OS Module Right here. Now the next thing I want to look at is traversing directories. Now before we traverse the directories, I want to create a directory structure specific. For this example, I’m going to open up my Finder window and go to the desktop and let’s create a well, I have the My folder folder here, and I think from the previous lesson we removed some of the files and folders that was inside of this folder, right? So what I’m going to do…
Python Institute PCAP – File IO and Exception Handling in Python
Exception Handling And it does exactly what it sounds like. Let’s say you have a user using your application or website or whatever, and they perform some kind of task and all of a sudden there’s some kind of error. Okay? We’d like our application to ideally handle that error in a graceful manner, right? You don’t want the user of your application to get, see, a scary message that exposes the internal code of your application. That’s really bad, right? Poorly designed websites go through this where if there’s…