Latest Posts
Python Institute PCAP – Modules, Packages and Object Oriented Programming in Python Part 5
Python Packages Using Python modules. And all modules are is basically Python files with Python code in them. Another higher level way of organizing your code is into packages. And a package is basically just a collection of modules in directories that give it a sort of a package hierarchy. So you can have a folder within a folder within a folder that contains modules or Python files, and each of those folders can further have their own files in them. So hopefully you get the idea. So let’s go…
Python Institute PCAP – Modules, Packages and Object Oriented Programming in Python Part 4
Double Under (Dunder) Methods And these methods are used to enhance the features of our class. So we’ve been creating basic classes so far. And when we create an instance of that class, when we print it out, it doesn’t even give us a useful representation. So, for example, if I create a class called employee and I define the init method, make sure you use the def keyword before that. And let’s say to instantiate an employee, we need to give a name and age. And so we could…
Python Institute PCAP – Modules, Packages and Object Oriented Programming in Python Part 3
Abstract Classes and Methods Now what’s? An abstract class. Well, an abstract class is a kind of class that is not supposed to be used for creating objects from okay, you cannot create an instance of an abstract class meaning you can’t create an object out of an abstract class you’re not supposed to. Now, python does allow a little bit of this, and then you have to kind of design your program in such a way that it throws an error when someone tries to do anything with an…
Python Institute PCAP – Modules, Packages and Object Oriented Programming in Python Part 2
Classes Attributes vs Object Attributes Constructor, right, which is supposed to construct the object. And what are the two values that are needed to construct an object properly? We have a body type and then the make, okay? And this could be a very long list of values that are needed to construct depending on how you define a vehicle. So we want to keep things simple. And we only have two values here. This self, it’s just an automatic thing. We need to have the self be the first…
Python Institute PCAP – Modules, Packages and Object Oriented Programming in Python
Revisiting the Difference between Methods and Functions So to start with discussing object orientation, I want to make a distinction between functions and methods because I’ve used these terms so far in the course. And we’re going to build upon this and you’re going to understand why. What’s the difference between a function and a method? So let’s start with an example of a list, okay? And we’ll call it my list. And so this has numbers from three to four. Whatever this list, I can pop things from this…
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…