Transcripts
1. Introduction: Careers in programming are on the rise and there are many opportunities for well-paying, interesting jobs that provide a good work-life balance. In this class, you'll learn what programming is and how to use it to tell the computer to do what you want it to do. We'll do this without immediately diving into all the nitty-gritty details that can be so daunting and scary. My name is Mary and I'm a professional software developer. I've been mentoring junior developers for a few years now. And I want to lower the barrier to entry into this exciting field for those without a technical background, this class is for those who haven't yet learned to program, but either want to get there or want to at least understand what it is. It's great for designers are managers who want to more effectively communicate with the programmers they work with. It's also good for anyone who enjoys visual learning and wants to know what programming is. You'll be able to use the skills you learn in this class to better communicate with software developers or to jumpstart your own programming journey. By the end, you'll be able to read through a short Python program that will write together and know what each line is doing. There's a lot of fun to be had. So let's get started with.
2. What is Programming: What is programming? Programming is a way to tell a computer to do exactly what you want it to do. Think the instructions that you might give your friend who you've entrusted to care for a Franny, you're high maintenance French bulldog. You might be a little vague about it. Trusting your friend's judgement. If your friend were a computer, the instructions would have to be a lot more specific. Take her for a morning walk isn't enough. You have to define when it's morning, maybe between six AM and nine AM. You have to say how long the WACC needs to be, maybe between 515 minutes or until she goes to the bathroom but no longer than an hour, even if she doesn't go to the bathroom. This level of detail can be quite intimidating. And to tell your friend all this, you wouldn't use regular words. You would only use special words that you know they understand to help us understand roughly how we might try to frame our logic using code. Let's have a look at some pseudocode. It's not real code, it's pseudo because it doesn't follow any particular programming languages valid set of grammar rules. These rules are called syntax, and we'll talk more about them later. For simplicity sake, let's focus on a single step in the instructions. All you want your friend to do is take Franny out for a walk once every morning. So every once in a while, if your friend sends you a message saying, Hey, should I go for a walk right now? And every time you answer, if the time is greater than six AM and the time is less than nine AM, meaning it's between those times. And Franny hasn't gone out today. Take a walk, otherwise, stay inside. Nice. We broke down the logic of whether to go for a walk into three very concrete questions. That wasn't too complicated. And this is how this logic might look like in the programming language. Python. Ignore the setup and just look at the highlighted part. Looks pretty similar to our pseudocode. Hopefully that helps you understand what programming is a tool that we use to give instructions to a computer in the most unambiguous terms, we use Python for this example. But there are many different programming languages, kind of like how there are different language languages. Some languages are faster, some are easier to learn, some interact better with existing software, and some are absolute garbage, but they exist and we all just have to live with that. If you're interested in learning more about concepts that all of these languages have in common. Do you want us in the next video?
3. Welcome to Python: Throughout this class we're going to be talking about broad programming concepts that will be transferable from most popular languages that are being used today. But in order to help me do that, I'm going to use one specific language. Welcome to the world of Python. Python was first released in 1991, and it was named after the British comedy group Monty Python. I chose Python because it's one of the most popular programming languages. It's also one of the easier ones to read. Here you can see some Java code followed by some Python code doing the exact same thing. It's shorter, it's simpler and it's easier to understand. As we read our Python code, we're going to imagine that our little computer friend is reading it line by line and trying to understand what we want them to do. We'll learn about different categories of words that computer can understand. How to keep track of our data, how to organize our data into helpful groups. How to organize our code into reusable components. How our computer friend reads are instructions. And one popular way to structure our code. If you want to follow along with some of the examples and run your own code. You can do that online by going to program is.com. From there, select Python programming, followed by online compiler that'll bring you to something called a console. On the left side, you can write code. On the right, you can see the output of your code and any errors that it might produce. You have two options for a class project. You can either follow along as we learn new concepts and play around with code as you try to apply them or alternatively, and this is my recommended option. You can lean back, relax and try to understand as much as you can without getting worried. A fetal programming is something that can be quite scary at first and trying to understand everything immediately you can resolve being completely put off with it. This class is about giving you a higher overview of what programming is and it, after watching the whole class, you still feel confident and enthusiastic, but learning, you can re-watch this time writing your own code. So let's get to it.
4. Types: As you probably know, the words in the English language are divided into various parts of speech. We can say that nouns are one such category or type. And verbs, for example, are another. In much the same way. Each word in the code that you write fits into a type. And much like with proper grammar, there are rules that we have to follow when putting these words together to create a proper snippet of code. Let's take the Python code we wrote earlier and label some of the types. We can see what type each value is by asking the computer like this. There are a few keywords in the mix. Keywords are predefined reserved words. Keywords are special, and unlike the other types, we can't ask the computer to tell us what type they are because using them in an improper order place will result in a syntax error. They were part of the syntax of language. When you learn a new language, usually the first thing you learn are the keywords is time for walk and needs to p or methods. We have a whole video dedicated to this type later on, 69 and time are numbers. Time is a bit different because it's a reference to a number and not the number directly. We'll talk all about that in the next lesson. There isn't truly a number type in Python. 69 are actually integer types, that's numbers without decimals. There are also float types in Python. Those are used for numbers with decimals true and false or Booleans greater than and less than our mathematical operators. Franny again is a reference. In this case, we'll just say that Franny is of type dog. There's no example of this type here, but string types are also very useful. Strings are used to display text and you can spot them by the quotation marks that surround them. Okay, we did it. Now here's a fun little game. Did you ever fill out Mad Libs? It's where you come up with some words. And so long as they fit the correct categories, the story makes grammatical sense. We can do the same thing with our code. Values can be swapped out for members of the same type and the result will still be syntactically correct. We can plug in these new values and the code will still run without any errors. You can't do this with keywords or methods because they're the types that define the rules about which other types can go where, but you can't do it with all other types. We saw. There are exceptions to this rule. You can't divide by 0, for example, but overall, the code is grammatically or syntactically accurate so long as you match the types, it doesn't make sense to check if time is less than a dog or if time is less than a string. But we can't check that number is less than number for any number. In this video, we learned about datatypes and how knowing the values datatype and help us understand where in the code we can use it. In the next video, we'll get to talking about variables which help us free use our data. See you there.
5. Variables: Remember how we said time was kind of a number? Well, it's clearly not a number. Is it a string? We'll know because it doesn't have quotations around it. Time is a variable. Let's take a step back and try to empathize with our computer friend. As they read our code, they acquire knowledge, that knowledge is stored in memory. They're memory doesn't look like ours. So let's instead pretend is just an endless covered with every value they've ever seen stored individually in each of the shelves. A variable is something that points to one of those shelves. It says this value represents shelf 2 or shelf 14. If I say time equals 12, I'm saying the variable time is pointing to this spot, and this spot has the number 12 in it. When I say time equals one, I'm changing where the variable time is pointing. I'm not rearranging the shelves. This is important to understand. So that code like this doesn't confuse you. X is equal to Franny. Y is equal to x. X is equal to Alpha. What does y equal? Is it Franny or is it Alfie? Think about it for a second. Let's look at what happens as we go through each line of code and see if it's easier to reason about that way. X is pointing to shelf one, which has the string Franny in it. We want y to point to the same value that x is pointing to. So we follow it and see that it's pointing to shelf one. Now we tell X to point to shelf to y is still pointing to shelf one, even though x is pointing somewhere else now. So y is still equal to Franny. Nice. Hopefully this video has helped you understand what a variable is. They're incredibly useful for many reasons. We didn't even touch on, like avoiding duplication and improving code readability. In the next video, we'll talk about another helpful tool for storing data. Join us there and learn about data structures.
6. Data Structures: We haven't seen these in our code yet. But data structures like variables are another way to hold onto data. But they go a step further and allow us to group our data in helpful ways. There are many kinds of data structures, but here we'll discuss the two most common ones, lists and dictionaries. For our first problem, we want to store all the grocery items to take care of Frannie for the week. For that, we'll use a list. A list is a data structure in Python that allows us to store multiple items together in a particular order. You can add all kinds of things to a Python list, strings, numbers, booleans, even other lists. Now that we have a list of what we want to buy, we can tell the computer to get everything on the list, or we can tell it to buy everything on the list but in reverse order, just for fun. For a second problem, we want to start the names of the parks that the computer can visit with Franny and how far away they are from the house. We could store the names in the list like this, but where do we put the distance from the house? Add that to a separate list. Well, we could, but now that information is separated and we don't know which distance corresponds to which part. For this kind of problem, we would use a dictionary. A dictionary is a key value storage are key in this case would be the park name and our value would be the distance. Now, each distance is very much tied to the park then it's describing. We can now tell the computer to go to the closest park or the one that's farthest away. Hopefully, you can see how data structures are handy when dealing with data. In the next video, we'll talk about maths and how they help us reuse our code.
7. Methods: Let's pretend we have a bunch of different buttons. And when we hit them, they do different things. We have the Hello button and also one that says goodbye. A method is kind of like buttons, but instead of pushing it, you have to call it. Now imagine a button that measures how hard you push it. If you push it lightly, it'll say, Ouch. If you push it harder, it'll say that hurts. And if you hit it really hard, it will scream, Oh no, I'm being attacked. That sensitive button isn't just responding to you, but it's taking input from how you're interacting with it. We can also give methods input when we call them. This input has to be defined by the method and this called a parameter in Python that looks like this. We're defining a method named Hello and will accept one input parameter and call it rating. We can also define multiple parameters like this. And to push our button and make the code inside it execute, we have to call it like this. You can spot a method when you see the def keyword code written inside of a method won't run until you call it. We'll talk about the order that our computer friend reads are coded in the next video.
8. Execution Flow: If you look directly to the left of our code, you can see that each line has a number of side. This is the line number and is often used by the computer to refer to our code and error messages. So how does the computer read our code? It reads our code starting at line 1 and moving down from left to right. If nothing crazy happens, the execution flow will go from line one to two, all the way down to the end of the file. But crazy things always happen. There are many events I can make the execution flow jump to a different line number and we'll go through them together. We'll start with definitions. Remember how in order for the code in our method is to actually run, we have to call them. That's because when the computer sees a method definition, it doesn't run the code inside the method. The execution flow looks something like this. It sees the method and notes down that a method by that name exists. And then salons all the syntax is correct. It skips to the line that comes after the method definition ends in Python and knows where that is by following the indentation rules. And other languages, there are often keywords are characters that specify the end of the method definition. So method definitions result in a jump in the execution flow, but so do method calls. When the computer sees a method call, it checks to see if a method by that name exists. And if it does, it jumps right into the code at previously ignored, right into the method definition. It then goes through the definition line by line until it reaches the end, at which point it jumps back to the line where the method was called from the next execution flow breaking culprit is a conditional statement. You've seen conditionals in our code before. One example is an if statement. The computer gets to a line that starts with ETH and checks. Is the value that follows it, true or false? Is x greater than five? Let's say that x is 10. So yes, it's greater. At this point. It'll jump into the next line and run the code there. For once it reaches the else statement, it'll skip it and everything inside it entirely. Alternatively, if x were one, then the statement x is greater than five is false. In this scenario, it would immediately skip everything inside the first indentation that follows the if statement and move immediately to the one following the else. Next or loops. We briefly saw loop when we ask the computer to buy all the grocery items on our list. What's happening here is we're telling the computer run this code as many times as there are items in the list. In our case, that's three times. And so the execution flow goes like this. It reaches the for-loop and sees the instructions, and then runs the code inside the loop three times. Then it runs the code on the line following the loop. Pretty simple. Return statements are used to, you guessed it, return. More specifically, they're used to return values back to the method callers. So if I call a method, the execution flow, as we've already covered, jumps to the method definition. Before I said that it waits until the end of the method to return to the caller. But there's actually a special keyword you could use to make it go back sooner and that's return. In this code, you can see that we're trying to set a variable to method. But how does that work? Well, the computer gets to this line, then it jumps to the method definition. Once it reaches the return statement, it jumps back to the method call. But with a value to set. If we take a quick journey back to our variables lesson, this is what this will look like in the computer's memory. Finally, we have exceptions. The computer will go through the code line by line. But if something wild happens that it doesn't know how to interpret someone trying to divide by 0, for example. It won't just keep chugging along. It'll stop everything and go all the way to the end of the program. And then it'll tell us that something went badly and that'll tell us where that happened. That's all right as a key issue flow, pretty fun stuff. Hey, you're almost done. In the next video, we'll talk about the role of classes in object-oriented programming.
9. Object Oriented Programming: Object-oriented programming is a programming methodology that focuses on objects and their relationships. An object is a collection of data and logic that act on that data. So how do we make objects full of data and logic? First, we make their blueprints. Remember how in our code Franny was of type dog. That's because to create her, we use the dog blueprints or rather the dog class. The class definition tells us what kind of data we can store on the object and what kind of logic or response to. A class is a blueprint for an object, similar to blueprints for a house. It contains all the details about the floors, doors, windows, whatever else. And based on these descriptions, we built the house, houses the object, the blueprint is the class. In the same way that many houses can be made from a single blueprint, we can create many objects from a class. An object is an instance of a class, and the act of creating the object is called instantiation. Okay, So there are two pretty confusing things about classes. First, to instantiate a new object from a class called schedule, we have to run this. This runs the init method of the class and is unlike previous method calls, we've seen where we use the name of the method to call it. It's a special case. And number two, you can see that the net method, as well as all the other methods on the class define a parameter named self. But we don't actually pass anything for this value when we call these methods. This is because class methods are special and they always have access to a variable named self, which references the object they are acting on. Confusing, I know, but you can just ignore it for now. In our code, there are two examples of classes. One is a class name schedule and one is a class named Doug. When we instantiate a new instance of the dog class, we create a new dog and save the value passed as a parameter to the init method as the dog's name. This data now lives on the new Dog object that was created and can be accessed like this. On the dog class. We can also spot a method. Remember to look out for that def keyword. We can call this method on the dog object like this. Right now. All it's doing is returning true. But we can change it so that it interacts with the other data that's stored on our dog object. Object-oriented programming has become incredibly popular in recent years and is a great place for beginners to start up. But you're not that much of a beginner anymore RNA. If you look at the Python code we wrote earlier, there's a good chance that you understand pretty much all of it if you feel like it, join me in the next video to find out what you can do to continue your programming journey.
10. Next Steps: That was quite the wild or head. I know it was a lot and it's totally okay if you didn't catch it on. The idea of this course is to give you an overview of what programming is. And if you feel like digging deeper, now you have a nice foundation to stand up if you watch the class without following along as I recommended. Now you can download the course files. They contain all the code that we wrote, along with a few corrections. You can run the code on the online compiler and watch the course again, this time following along and playing around with print statements. And if you don't like doing that, There's also a questionnaire available to help you test your knowledge that way. If you want a more structured approach for learning Python, I recommend this course. Dummy. Please write a class and let me know what I can do to improve it for others. Thanks for watching and have a great day. So let's get to it. Or, you know, it helps me with my cats. Oh sorry. No, it's infinity stone as a fast recently by the lessee rises to if I didn't get cake, I do. I hit. Okay.