Skip to content
CBT Nuggets
DemoBook a Demo

Introduction to Programming and Python

This skill provides an introduction to programming with a focus on Python. It covers fundamental concepts such as what programming is, the importance of programming languages, and how to write and execute Python code. The skill also includes practical steps for installing Python on various operating systems, configuring environment variables, and choosing the right code editor. Additionally, it explains the process of compiling code and the differences between compiled and interpreted languages.

Full skill from PCAP certification. Preview the training IT teams trust.

Updated

57m

Skill 1 of 15 in PCAP certification

What you'll learn

  • Explain what programming is and why computers need precise, unambiguous instructions to execute
  • Compare compiled executables with interpreted Python source code and explain the portability trade-offs
  • Install Python 3 from python.org and test commands in the interactive Python terminal
  • Configure the PATH environment variable so the intended Python version runs when multiple versions are installed
  • Choose between a lightweight code editor such as VS Code and a full IDE, and add Python extensions
  • Write and run a Python script that accepts user input into a variable and prints a greeting

Free 57-minute video lesson with a full transcript and knowledge checks. No account needed to watch.

Overview

Join Ben Finkel as he takes a high-level conceptual approach to programming.

Gain an understanding of what a programming language is and why they work the way they do.

Recommended Experience

  • Familiarity with a programming language is recommended, but not required

Related Certifications

  • Certified Associate in Python Programming

Related Job Functions

  • IT professional
  • Software developer
  • Network engineer
  • DevOps engineer

Ben Finkel has been a CBT Nuggets trainer since 2014. His areas of expertise include Google Developer Expert, Google Certified Trainer, Microsoft ASP.NET (WebForms and MVC), Data Analysis and Design, Relational Database Architecture, MS SQL Server, Microsoft C#.NET, Javascript, jQuery, Microsoft Visual Basic .NET & 6.0, .NET Reporting Services, MS Access, and Python.

Supplemental File

Wherefore Art Thou Programming?

Why do we program in abstract programming languages? What is the point of programming in the first place? In this introductory video we'll take a basics-first approach to answering those questions!

Knowledge Check

Computers store everything as a series of zeroes and ones, known as binary. True or false?

Compiling Code into Executables

Source code is not binary code and cannot be run by a computer. How do we turn it into useful commands for a device? Compiling!

Knowledge Check

Which of the following is the term for the semi-compiled state that Python code is distributed in?

Installing Python 3

Python is very easy to install as we'll demonstrate in this video for the three major platforms: Windows, MacOS, and Linux.

Knowledge Check

Which of the following platforms support Python 3? (Choose three)

Select all that apply.

Configuring the PATH variable

Environment variables are a key piece of system administration and using Python effectively means knowing how the PATH variable works on your platform.

Knowledge Check

The System PATH variable will take precedence over the User PATH variable if both are defined. True or false?

Choosing a Code Editor

Your code editor of choice is an important one, and while you'll likely change over time it's good to know what the options are available to you.

Knowledge Check

Source code is written and stored as plain text ASCII files. True or false?

Writing our First Program

In this video we'll combine everything we did previously to write our first Python program.

Knowledge Check

Which of the following is most true about programming?

Conclusion

I hope this has been informative for you and I would like to thank you for consuming.

View Transcript

Wherefore Art Thou Programming?

0:05Welcome, everyone. You're here today because you want to learn a little bit of something about programming. And I want to talk quite a bit about programming itself. The act of developing programs and applications for our computers. Now, you may have an idea of what programming is, you may have even done some programming and some scripting in the past, it's certainly a very common thing to have done. So you may have done that, but even if you haven't, this is a perfect place to start. I want to level set exactly what we're talking about when we talk about programming so that we're all approaching it from the same mindset, in the same direction.

0:37And we understand the vocabulary that we're using and why we're doing what we're doing and really just answer the question initially here, what the heck is programming? What in tarnation are we doing? And I think the answer to that question is actually relatively straightforward, although as always with computers, the devil is in the details. Programming is just the act of providing a set of instructions that the computer can run. The computer can execute-- is the term we often use. When a computer program runs, we say it's executing. And all we're doing is saying, hey computer, this is what I want you to do.

1:09Why is this important? Well, computers don't know what to do on their own. They need someone to tell them what they should be doing, how to respond to different user interactions, where to get data from, what to add up or subtract, or when to show the cool graphics. All of this stuff gets supplied to the computer by a programmer using something called a programming language. I think you've probably heard of some programming languages before in the past. A programming language is nothing more than a language that we can use to communicate those instructions to the computer very concisely and very clearly and very explicitly.

1:42Now I want to unpack this a little bit. Why do we need to use these programming languages? Why do we have to be so explicit and concise? And the answer to that question is because, well, one of my favorite phrases and this could probably be the mantra for this entire set of videos, computers are dumb. I know. You don't think they're dumb, right? Most people don't. They're like, computers are amazing. They can do all those crazy things I was just talking about it a moment ago, right? They can calculate pi out to 6,000 digits in the time it takes you to type in the letters p and i. They can play amazing graphical video games with all sorts of crazy physics going on.

2:14They can do an enormous number of things really, really well. But the simple fact of the matter is they can only do those things when they've been instructed to. Someone had to figure out how to do those first and tell the computer to do that. And a lot of those things aren't really all that complex when it gets right down to it. I mean sure it can calculate pi up to 6,000 digits. But so can I? It just takes me a lot longer. That means the computer is not necessarily smart. The computer is just fast. And that's what you need to understand. Computers are very, very fast, but they're also not very smart.

2:45Computers are dumb. And they don't handle things like ambiguity or uncertainty or contradictions very well at all. A computer needs things laid out very explicitly. A computer wants to know what it's supposed to do, when it's supposed to do it, and you need to be as direct and explicit as possible. If you give some ambiguous instructions to a computer, well, best case scenario the computer is going to interpret those instructions in a way that you did not intend and has some sort of unintentional consequences, it's not going to operate the way that you thought it would operate. Worst case scenario, it's going to crash.

3:16Right, the whole computer is going to come down. The system is going to stop. The operating system is going to stop. I think you've probably worked on a computer system in the past that has crashed, certainly not an uncommon operation, that's because the computer ran into some instructions and ran into some code that it didn't understand how to deal with or how to handle and it just threw up its hands in the air said, fine I don't know what to do with this. I'm just going to give up. So computers-- yes computers are dumb. I want you to remember that and keep that in mind. So how do we communicate instructions to a dumb computer. Well, you may be thinking, hey, I speak English.

3:47I can use English, right? I'm pretty great at communicating instructions say to my children when I want them to get dressed and put their shoes on and get ready for school. I mean I can 4-year-old how to get ready for school. Surely I can computer how to calculate the pi. Well, it's not as easy as all that. Right? The languages that we use to communicate with each other and to other people are called the natural languages. And this is because they have naturally evolved in the human species. We're talking about all the language that we speak English, Mandarin, Russian. Whatever language you talk, these are the natural languages. And natural languages are great at conveying all of the intricate complexity of human emotion in our inherent contradictions in all of these different ambiguous things.

4:26We use not just our language, but our hands, we use facial expressions. And all of this combines to make a really powerful communication platform for people. But computers don't really deal well with that. Computers can't read the emotion out of your eyebrows. Computers cannot understand what your hands moving in a particular way might mean or how that inflects what it is you're saying. No, computers need things very, very explicit. And I think you've probably run into this before as well. You've heard of binary right? Zeros and ones. Every instruction, every application, everything that runs on a computer is ultimately stored in binary and as a bunch of code that is made up of zeros and ones.

5:05And that is how computers interpret everything. Why is binary so powerful? Because binary is unambiguous. There is no room for ambiguity in binary. It's either a zero or a one. It's on or off. It's true or false. It's yes or no. It can't be halfway between true or false. You can have something that's halfway between 0 and technically you've got 0.5, but the computer, it's binary code doesn't know how to deal with that. It's either one thing or the other thing, which is a very clear cut and very direct and very precise. And that's very important for computers to do their thing, for computers to operate.

5:38What's the problem here? Well, of course people cannot speak binary. So we think about the gap between these two things, the natural languages and the binary languages. Where do people come into play? I mean, after all, I can't write binary code and to be perfectly clear nobody does actually write binary code. That's not a thing that happens. Worst case scenario people write something known as machine language. But the simple fact of the matter is binary is too verbose. It's too long. It would take thousands of digits just to express a simple basic instruction like adding two numbers together.

6:09So we can't write binary. People cannot write in binary code. But if people can't write binary and computers can't understand English, what's the answer? What's the compromise? Well, the compromise is what we call a higher order programming language. And we are going to talk specifically in this set of videos about one of them Python, although there are many programming languages out there. I've got a few examples up here in the upper C-Sharp, Java, Perl, .NET. You may have heard of some of these, some of them may be new to you. There are quite literally hundreds of viable programming languages out there.

6:40We're going to choose Python for a number of reasons I'll talk about in another video. So a programming language like Python is a compromise. Is a compromise between these two extremes. Between the natural languages and the preciseness of binary. It's strict enough for computers. So we can very explicitly state what we want to state to the computer, what we want it to do. But it's relaxed enough that humans can both understand it as well as write the code. A programming language-- a code that you use to instruct the computer is going to look somewhat legible.

7:10Somewhat readable. It will look kind of similar to the English language in this case. It's going to follow largely the rules of the English language. We're going to read it top to bottom, individual lines get read left to right, you'll see words like if and then and loop that you recognize from the English language although they have very precise specific meanings. You'll also see some constructs that don't make any sense at all. You'll see colons and parentheses and curly braces all used in places where you would not expect them. So there's going to be a lot of structure and rigidity, and we're going to have a very limited vocabulary of things that we can say with our programming language.

7:43So it is not a full fledged natural language. You couldn't really use a programming language to communicate between two people. It compromises between those two. It comes up with a decent way to make language or code that humans can read and write but will also be able to be ultimately interpreted by computers as a collection of zeros and ones. So that is what programming is. And that is ultimately why we use programming languages to program our computers, because say it with me, computers are dumb. They need us to be very precise, very explicit in what we want them to do.

8:15If we give them ambiguous directions, if we create some uncertainty, who knows what's going to happen? We certainly don't, so we want to avoid that as much as humanly possible. I hope this has been informative for you and I'd like to thank you for viewing.

Compiling Code into Executables

0:05You'd like to start writing some code. I don't blame you. I want to start writing code with you. We are so close. We're almost ready to go. But we do need to level set a little bit more. There is a thread, a loose angle, that I left a little bit open in my last video-- a question that was unanswered. And if you didn't notice it, well, that's OK because I didn't explicitly ask the question. You would have had to been paying very close attention to pick up on it. But let's refresh. What did I talk about in my last video? Well, I talked about the fact that computers only use binary code.

0:36But we need to write in something like a programming language so that we can understand what we're writing. And then the computers can interpret it and execute it, what we meant. But if we're writing Python code and the computer needs 1's and 0's, binary code, there's a gap there. How does my Python code, or how does my C code, or how does my Java code get converted into binary? Well, the answer is a separate step, a process called compiling. When we compile our software, we take our source code, which is actually just written in plain text, just ASCII text-- most source code can be opened in a software, like, Notepad, right?

1:12It's just plain text file. And it converts that into a binary executable file. Let's talk a little bit about what that means. Imagine you want to feed someone a cake. Well, you don't have a cake. What you've got are a bunch of ingredients-- sugar, eggs flour, milk, whatever is going into the cake. You can't eat these things. I can eat these things, right? I'm not eating spoonfuls of raw flour. I'm not cracking eggs into my mouth. I want a cake. But in order to get a cake, I have to take my raw ingredients, and I've got to do some additional steps, right?

1:42I've got to mix them up. I've got to bake them in the oven. And then at the end of all that processing, now I've got a cake, a cake that can actually be consumed by a person. Well, I like this analogy. This is a good analogy for our source code, which is like our raw ingredients. That's the code that we are going to write. Our Python, our C, whatever code we're writing, is going to be our source code, plain text, inedible for the computer. The computer cannot eat that source code. We have to go through this extra step of compiling before we get the 1's and 0's, the binary code, which is also known as an executable.

2:15And you can see this on your computer. If you have any software installed on your computer, there is an executable. For instance, I'm going to bring up my File Explorer in Windows here. And let's just look inside of my Microsoft Office folder. I happen to know where this is. So I'm going to drill down into the specific location where it's found. Look at C Office-- nope, not 15-- 16, right? Yeah, there it is. If I scroll down to the Es, I see-- look at this-- EXCEL.EXE. Application type, the size is 62 megabytes-- a fairly large binary file. That file right there, EXCEL.EXE, is a binary executable.

2:48That is the 0 and 1 instructions that the computer needs in order to run the Microsoft Excel program. That's where it's all contained. That's where the magic is. And this is true regardless of whether you're on Windows or Linux or Mac. There's always a binary executable file that has to contain all of those instructions. It's not something you can look at. If I try to open it up with-- let's see here-- something, like, Notepad, look at this total gobbledygook garbage. This is not understandable. And that's because that EXCEL.EXE is not a text file.

3:19That EXCEL.EXE is a binary executable file. This is the result of the Microsoft Excel source code being compiled and being delivered to the end user. And that's really, at the end of the day, what you should be thinking about here. All of these steps prior to the actual cake is being done by the developers. It's being done by the person delivering the software. In the case of Microsoft Excel, that's Microsoft. They write the source code. They go through the compilation step. And they deliver to you, the end user, an executable file. That is how programming, that is how code, works.

3:51At least that's how it works most of the time. Now, there are some scenarios where that's not quite exactly how it works. And Python is one of those scenarios. Python-- when you write Python code, it does not compile all the way to a binary executable. Python splits up the work a little bit into a couple of different separate steps. Now, at the end of the day, we still have the same basic things. We still have our source code ingredients written in Python. And we still have our final cake that is a binary file. But what we do for Python, as well as other languages, such as Java or .NET, is we only partially compile it.

4:26We only take it a part of the way and turn it into something called bytecode. Now, we won't get too in depth. But a bytecode file is not binary. It's not a binary file. It's not an executable. A bytecode file is not yet ready to be executed by a computer. We ship this bytecode file to the end user. And they have an interpreter installed in their machine that performs the final execution, the final compilation of that bytecode into a binary file in real time, while the file is being executed, while it's being run.

4:57We call this, sometimes, just-in-time execution, or just-in-time compiling. This means that our code is not quite finished. It's not quite baked. It's parbaked. If you've ever had a parbaked cake or parbaked cookies from the bakery, you know that they come partially baked but not all the way baked. You need to bring them home, put them in the oven and finish cooking them. That's exactly what happens with Python. So the whole process still has to happen. We just ship the last final step of that. We rely on the last final step of the process to happen at the end user's computer, the end user's device, when they actually want to execute the code, when they want to run the program.

5:33So Python code gets converted to bytecode. This is the process for what we're going through here. Python code gets converted to bytecode. The bytecode is delivered to the end user. And an interpreter, a piece of software on the end user's machine, finishes running that code. There's a really important piece that is buried in all of this, I think, that you need to understand. And that is the fact that every computer, every device, every machine that wants to run Python code, at the end of the day, needs to have that interpreter installed. When I compile a C application for saving Microsoft Windows platform, well, anyone who has Microsoft Windows installed on their machine, I know is going to be able to run that application that I delivered to them.

6:12That's what it needs. As long as it has Microsoft Windows, it'll be able to run that. Not necessarily so with a Python application. They need not only their operating system, like, Windows or Mac or whatever it is, they also need the Python interpreter installed in order to run my Python code. That's a really important thing to understand. It's a really important part of what we're doing here. And it informs, well, really, it informs the reason that we do this to begin with. I mean, after all, what's the point of only doing this parbaked, partially compiled code and shipping that to the user? So let's compare compiling code to an executable versus bytecode.

6:44When you compile code to an executable, the executable is absolutely going to run faster. And it's going to be more efficient in memory usage. Compiled code, compiled executable, beats out bytecode on both of those particular notes. So why do we do it? Well, because bytecode is platform independent-- it is portable. It can be delivered to a number of different systems. The basic idea here is that we have write-once code base so that we can only manage a single code base and deliver a single compiled bytecode executable to all of our different target machines.

7:21Let me expand on this little. When you compile an executable, say, in the C++ programming language, if you write an application in C++, and you compile, let's say, for Microsoft Windows, let's say you compile it from Microsoft Windows 10. That's only going to run on Microsoft Windows 10. Microsoft is good. It will probably run on Windows 7. Maybe it will. Maybe it won't. It definitely will not run on, say, Macintosh OS. It will not run on iOS or Android or Linux or any other platform. If you want to compile that code for one of those platforms, you've got to go back and recompile it with a new target environment, a new target platform.

7:52So you have to deliver different executable files to different users on different platforms. And if your code has some instruction for a given platform that is not supported by another platform-- so I've written some code that works in Windows but not in macOS-- I can't deliver. I can't compile that into a macOS executable. I'm going to have to maintain a separate code base. Now I have two copies of my source code-- one for Windows, one for Mac. Maybe three-- now I need one for Android. I need one for iOS. I need all these different copies of my source code. I have to compile them all independently and separately, and deliver them independently and separately, to the appropriate users on the appropriate platforms.

8:28Sometimes that's ideal. There are certain situations where that's fine, and you don't mind going through that extra legwork to get the speed and efficiency gains that a compiled executable gives you. But sometimes that's not what you want. If you don't have a good handle on who your customers are going to be or what platform they're going to be running on, you can use something, like, Python or Java or .NET to write your code one time and one time only-- one single code base, compiled to one single bytecode. And you deliver that bytecode to the end user. You are relying on the interpreter on the end user's machine, to handle all the complexities of actually compiling that for the end user's device.

8:59You don't need to worry about it. If you have some source code that works in Windows and not in macOS, you deliver it anyways because the compiler is going to handle not executing that source code. It will gracefully handle what to do in that particular scenario. As a developer, you don't have to maintain separate copies of your source code. You don't have to deliver different versions of your executable depending on your target user's platform. So you gain a lot of flexibility, a lot of portability, when you use code in this way, when you use this method for compiling your code. So that was all a lot if you're not familiar with compiling and what we're talking about here.

9:31I talked about a lot of things. Let me break it down for you one more time before we sign off. When you write code, you write source code in plain text. And, in fact, when we write our first Python program, I'm going to write it in Notepad just to show that off. Typically you'll use something nicer than Notepad. But it is just a plain ASCII text file of code, of instructions, for the computer. That has to get converted into binary code, into the 0's and 1's that the computer can execute. And that is done through a step called compiling. Most traditional programming languages get compiled all the way to a binary executable that is delivered to a target end user's machine for the platform that they're running, whether it's Windows or Mac or iOS.

10:08Some programming languages, notably, Java, .NET, and Python, which we are working with here, only partially compile the code. They compile it into something called bytecode. And the end compilation is actually performed on the end user's machine while they're executing, while they're running the application. They do need an interpreter. They do need a virtual machine of some sort running on their computer in order to interpret that bytecode, In order to run that code. So you are relying on the end user already having that support software on their device when you ship them a piece of, say, code written in the Python language.

10:42I hope this has been informative for you. And I'd like to thank you for viewing.

Installing Python 3

0:05All right, I don't know about you, but I am ready to start hitting the road here. Let's get started with Python. And the first thing that we need to do-- well, we need to install Python itself. The Python download can be found at python.org. And we're going to download a package and walk through the wizard. I'll do this on both Windows, macOS, as well as Linux. So you can see it install on all three. They all largely work the same, but there are some unique properties for each platform. So depending on which platform you're using, you're going to need to follow slightly different installation instructions. Now, there's a few different things included in the package when we download and install Python.

0:40First of all, of course, our Python interpreter. Recall that we said in our previous video, you can't run Python code without a Python interpreter installed. Unlike a fully compiled executable, you need a Python interpreter that can actually read and understand the bytecode that gets delivered and then in turn execute that on the target machine. The target machine in this case is going of the our computer. So the Python interpreter is installed. There's also something known as an integrated development environment for Python called IDLE. This is a very simple IDE. I'm going to show it briefly in another video, but I don't think we're really going to use that much.

1:12Certainly, if you want to use IDLE, you're welcome to, but you don't need to worry too much about it. Just know that that's an environment where you can type Python code in, and it has some shortcuts and useful features and utilities that will help you write Python code. The Python installer also has something called pip, the package installer. This is how we install additional separate utilities that are not actually included in the Python 3 downloads. So there is a whole universe of libraries and updates and options and features and things that Python themselves have developed, as well as the wider community.

1:42There's thousands and thousands and thousands of packages out there that you can download that do things for you. Pip is going to be the way that you get a hold of those packages and install them on your system so that you can use them inside of your Python code. We'll get the standard libraries installed as well. So aside from the pip package installer, there is a host of libraries that get shipped standard with Python and are installed with the Python software. Those will come. And then lastly, it is going to set up our file and path associations. That's a feature I'm going to talk about in a different video, but that's a really important thing to understand to set up in your Python installation.

2:19To begin with, I am going to open up python.org and come over here to Downloads. And I'm going to download Python. Well, the current version is 3.9.2. Note that it cannot be used on Windows 7 or earlier. So if you are not on Windows, this should pop up with the appropriate platform for you, either macOS or Windows. I'll click Download so I can download this file. And once it's complete, I will click it to execute it and go through the installation process. Now, you can just click this Install Now if you want. That will install with all the default features. There's absolutely nothing wrong with that.

2:50The only thing I don't like here is where it chooses to install the software. It's buried down here instead of my user profile on Windows. I'm not a huge fan of that. I'm going to say customize installation. I'm going to leave everything the way it was except for this part right here. I'm going to change this to C colon backslash Python39. This is going to install it inside of the Python39 folder on my root C drive on my computer. And as I will show you in a minute, there's a lot. I'll also check Install for all users. I think that'll be good. Click Install.

3:21And this will install Python for me. Very simple and straightforward, not a difficult thing to do on any of these platforms. It's pretty streamlined. The process, it's fairly easy to do. That took a few minutes to complete, but once it's done, you get the "Setup was successful." And Python is now installed on your machine. I will show you how to check that out in just a moment. Let's walk through this same process, however, on Macintosh OS. Here is my Mac OS desktop, and same thing, I'm at python.org. If I come over here to Downloads, notice now it's Download for Mac OS X. Click the link and let that download.

3:57And once it's done, I will select it in order to kick off my download. Now for Mac, I am just going to click through all of the wizard options. I don't think there's anything that I'm really interested in changing, including the install location-- not something I need to update on my Macintosh system. I'm just going to let it install Python 3.9. Once again, this should just take a second or two. And there it is. It's complete. It's showing me the file. Notice there's the IDLE application, that IDE that we talked about, Python documentation, a launcher, a number of different things here.

4:30We're almost ready to get into it. Let's take one more quick look at how I do this in the Ubuntu software, Linux. Now, unfortunately, Linux is too rich and varied of an environment for us to really make a universal installer video. I'm going to show off how you do it in Ubuntu using the APT software. This is a pretty common way to do things. So it may well work on the version of Linux, the distribution that you're using. If it doesn't, you're going to have to hit your favorite search engine and look up how to install Python. It ought to be pretty straightforward, pretty simple. So from my terminal, I am going to call apt-add-repository to add a specific repository to my APT.

5:08It's going to be something known as the deadsnakes, which is a funny name, but that is where the Python application is installed here. And once that catalog is installed inside of my package library, I can now call sudo apt install python3.9. This will install Python version 3.9 for me. Get this installed here. Once this is complete, I can verify at the terminal window that Python is installed. Let me show you how to do this quickly in my terminal here. Then I'll launch up my Windows terminal and show you a little bit about what we've done.

5:41So there. It appears to be complete. I'm going to call python3.9 --version. And this is going to show me that, yep, it responded with Python 3.9.2. I now have that installed. Let me open this up in Microsoft Windows and do something similar. So here I'm at a Command Prompt, a terminal window in Microsoft Windows. By the way, you can do the same kind of thing in macOS as well, if you're familiar with how to launch the terminal here. I'm just going to call python --version and see what I get.

6:11I get 3.7.4. And the reason for that is because of the fact that I have multiple versions of Python installed. And my path version currently points to version 3.4. If I go cd backslash python39, is where I installed it, take a look at this directory-- yeah, there's python.exe. So now when I run Python, it's going to run this local version. I'll talk about paths in the different local versions in my next video. But python --version in here is now Python 3.9.2.

6:41So if I want to execute Python 3.9, presently I've got to make sure I'm right here inside of this folder. I've got a lot of different versions of Python installed, like I said. If I go back to 27, I think I have 27 installed here as well. So I could call python --version 2.7.17. So like I said, I've got a number of different versions of Python installed. You may only have the one. But if you have multiple versions, you need to make sure that you either change into the proper directory or that you set up your path variable the way I'm going to show off in my next video. But here, all I want to do is run Python without --version.

7:14This launches me into something known as the interactive terminal. You see those three little arrow brackets there? In the interactive terminal, I can just start typing Python commands, and the Python interpreter will execute them as I type them, which is actually pretty cool. It's a neat way to test out quick little bits of code, which is exactly what we are going to do right here. If you've got Python installed, you have the correct version, you ran Python, you have these three little pips right here, you can do what I'm going to do, which is to say print("Hello World!") and hit Enter.

7:50And you can see, it just echoed right back to me, Hello World! OK, yeah, I get it. That's not especially exciting, but it is a traditional first program and that is absolutely a complete and functional Python program. Print("Hello World!"), that is a Python program. If you've done this, if you've gotten this far, you have written your first Python program, and we have written our first Python program together. In my next video, I'm going to talk a little bit more about configuring our environment and setting up the path, as well as the code editors that we want to use.

8:22I hope this has been informative for you, and I'd like to thank you for viewing.

Configuring the PATH variable

0:05I'd like to take a few moments here and dive into the weeds a little bit on some system administration, some configuration for our installation of Python. And I touched on it briefly in my previous video where we installed Python, but now I want to take a moment to really dig into it, and what it means, and what we saw. So here's what we're starting with. Python, when we install it, gets installed to a specific directory on our computer. It had a default directory. I actually overwrote it, if you recall and watched that video on me installing it. So I installed Python 3.9 to a specific directory.

0:36But we can only execute the Python interpreter, the python.exe file, to interpret and run our Python code if our user context is in that directory. And I'll show you what I mean by user context in a moment. We saw this briefly. When I launched Python --version after installing it and I was just in my root C folder, it returned version 3.7, not version 3.9. And that's because I had both 3.7 and 3.9 installed in my system. But specifically, there was something known as an environment variable that was pointed towards the Python 3.7 path.

1:08Now, we could have changed this. In our installation of Python, you may have noticed that I breezed past this screen. But during installation, we had this little option here, Add Python 3.9 to PATH. I do not check that. I would probably actually recommend that you do check that, but I specifically left it unchecked to put myself in this scenario so that I could show off exactly what has happened here. So what that means is that we need to open up and add Python 3.9 to our environment variables itself.

1:38I'm going to show you how to do this in Windows. I'll briefly take a look at it inside of Mac so that you can understand how it works in bash. Mac and Linux work largely the same. Windows is quite a bit different, although the functionality is the same across all of these different platforms. The first thing you're going to do, if you are on the Microsoft Windows platform, is open up your Start menu and type in environment variables to get this particular link up here, Edit the system environment variables. When you click that link, it will launch this particular window right here. And notice this button right in the bottom, Environment Variables.

2:10Environment variables are basically values that are available to the entire environment, the entire system. They come in two forms. You can see them here. At the top are the user variables, and at the bottom are the system variables. Basically, system variables always apply. User variables only apply to the specific user that is logged on. So user variables can change from user to user. I'm logged on as CBTBen right now. If a different user logged in, these values might be different for that user, whereas these values would all be the same because they apply to the entire system.

2:41Both of these have a specific variable that I'm interested in called PATH. And again, the user variables, if they duplicate up, will overwrite the PATH of the system variables, so keep that in mind. But let's take a look at the PATH variable itself. The PATH variable contains a number of different directories on my system and effectively makes the executables in those available from anywhere. So notice, Python37 is included right here-- C colon backslash Python37. Why is that important? Well, if I come here into my C colon and I type Python --version, what do I see?

3:16Python 3.7. I'm not in the Python 3.7 folder right now, I'm just in the root folder. But Windows recognized that it went through the script and it was able to find python.exe located in the 37 folder. If I were to remove this from my environment variables, so that now Python 3.7 is no longer located in there, check out what happens now if I actually close this and start up a new one. So this is a new command prompt. When I run Python --version now, I get, Python was not found.

3:46It can't see it. My user context is currently located in the root C colon folder, which means there is no python.exe file. I can only run Python if I change my directory into that folder. So if I cd backslash into Python39, for instance, now I can write python --version and get Python 3.9.2. But if I'm not inside that folder-- for instance, if I'm in a folder mysourcecode, how about, there's no Python installation here. In fact, there's nothing at all in this folder.

4:18I can't run Python from here. I get-- well, in this case, it tries to launch the Microsoft Store and install it. But it does not run the locally installed copy of this software. Now, there's a couple of solutions here. One, I could always just explicitly reference them using the full path name, so I can call python39 backslash python, like this, and this will execute the Python software for me by explicitly referring to the version that I want to run. If I change it-- instead of 39, if I go 36-- do I 36 installed? I don't. Oh, I have 3.8, I bet. python-- yeah, there's 3.8.2 installed in Python38.

4:50So I can always reference the specific version, the specific Python executable that I want to run by putting the full path in. But you know, that's a lot of typing. There's a lot of extra typing. And if you've only got one version of Python installed and you only ever need to run that one version of Python, why not just stick it inside of your PATH variable? Come here to Environment Variables. I'm going to come down to PATH right here and say Edit. And let's add a new entry here, C colon backslash Python39 backslash. I'll say OK, OK. I do need to restart my Command Prompt.

5:22And I will change directory into mysourcecode again. There we are. Now I can run python --version and it comes up with 3.9.2. Because I added it to the environment variable, Windows now searches that PATH, finds a Python executable, and runs it when I try to execute it here. We can also do something similar inside of other operating systems, such as Macintosh. So for instance, from my Macintosh computer here, if I launch my terminal window-- I have iTerm installed. I also have a user context.

5:53This launches me instead of my home directory, benjaminfinkel. And if I want to run Python, I call python --version-- yeah, 2.7.7. That is what's currently pointed towards in my PATH. How do I know? I can call echo $PATH, and that shows me all of the different folders, all the different locations that are included inside of my PATH variable. Now, I'm not going to spend a whole lot of time getting involved in the Linux and macOS PATH variables that are located in bash. You can look up Shawn Powers's excellent Linux administration course.

6:27And there's a video there about environment variables that covers all of this in depth. Functionally, it's effectively the same as what I just showed you inside of Windows. You need to have the actual location of the Python executable file inside of your PATH folder so that it can be run, it can be executed from any location, regardless of where you are inside of the terminal window. All this allows us to run Python from our Command Prompt, from our terminal windows, regardless of which folder in, regardless of which directory we're currently located in, so that we can put our source code in a different directory than the Python interpreter and so that we can have multiple versions of Python installed on our system and explicitly know when we want to run one version versus another.

7:07I hope this has been informative for you, and I'd like to thank you for viewing.

Choosing a Code Editor

0:05BEN FINKEL: If you have been following along with these videos, then you should have downloaded and installed Python on your system, opened up the Python interactive editor, and typed in a line of code and see it run. That's a cool thing to do. If you did that, give yourself a little applause. If that's the first code you've ever written, hey, that's a big step, and I don't mean to diminish it. But it is only the first step on a very long journey that is going to involve a lot of different things. And one of the first things that we wanna change is we don't want to spend a lot of time inside of that interactive editor. In fact, I'm not going to do that at all.

0:37I think you want to get out of the habit right away of using the interactive editor with Python. It's great to just hammer out a line of code or two, and see it run, and see how it works. But the second you get above more than like two or three lines of code, it's no longer really a useful interface to be working in. Instead, what you prefer to be doing is writing source code instead of a source code file, and then saving that file to your file system. Now, if you'll recall, I've mentioned a number of times during the series that source code is saved as plain ASCII text and saved as a plain ASCII text file on your file system.

1:09And this has a couple of different implications . The one that I've been talking about is the fact that source code files need to be compiled, either to bytecode or all the way to an executable, before they can actually be executed on an end user's system. But it also means that they're kind of universally portable. ASCII text, if you're unfamiliar, is just a plain basic text format that computers use. If you use Notepad in Windows, or I think it's called TextPad inside of macOS-- these are the types of files that those file editors edit. It's just plain text. And if you create a source code file, it's saved as ASCII text.

1:43While not technically universally portable, it's, in practice, universally portable, because almost every system out there-- every device, whether it's a tablet, a phone, a laptop, a desktop, whatever it is, cars and washing machines, anything that has a computer in it can probably read a text file. And that is true of your source code, as well. And what that means is that we could write our source code, if we wanted to, in something as simple as Notepad. You know Notepad, right? It's the basic editor that is built inside of Windows. It looks something like this. I got it on screen here.

2:13This is a Notepad editor. And yeah, actually, this is a functional Python program inside of Notepad. Don't worry about what this. Does we'll talk about it in a little bit. But the point is you could write your code inside of Notepad. I've done that exactly right here. I have this text written out, saved as samplecode1.py. I'm going to open up my command line, and inside of mysourcecode, I believe that's where I saved that file. Yep, samplecode1.py. I'm going to say python samplecode1.py. This is going to execute my Python interpreter, passing in that file.

2:43So instead of working in the interactive interface for my Python interpreter, I have code written to and saved to a file, and it's going to execute all of the code inside of that file for me. So we will click Enter here. "What is your name?" Well, my name is Ben. "How old am I?" Well, at the time of this writing, I'm 42. It says, "Hello Ben. You're old enough to vote in the US!" Hey, I am old enough to vote in the US. That's true. Let's test out this program. I'm going to run it one more time. "What is your name?" My name will be Dolly. "And how old are you?" What if Dolly is 17? "Hello Dolly.

3:14Wait a few more years before you can vote in the US." That's absolutely true. You can only vote in the US once you're 18 years old. So this code, this program was written here in Notepad. And yeah, OK, technically, yes, you can write your code, you can write your software in Notepad. I don't recommend that, either. I don't recommend it any more than I recommend using the interactive interface that comes with Python itself, because while yes, you can edit the actual text of your code, Notepad offers exactly zero additional features, zero support to help you write better code, or to help you understand the code that you're writing, or to help you navigate, and organize, and architect your code.

3:48There's a lot of benefits to using other tools, additional tools, for writing our code. So some of those tools are known as IDEs-- Integrated Development Environments. You may have heard of these. They're pretty popular. There's a lot of them out there. This is going to be things like Visual Studio, Eclipse, NetBeans. There's a lot of different IDEs out there. And IDEs are these really big, robust, complex but powerful, feature-rich tools. They allow you to do a lot. They are really designed and built from the ground up to write and architect large-scale enterprise applications and software.

4:25They will have built in harnesses for testing, for source code control, for bringing in libraries, for linking in different types of code and different types of software, even things like navigating databases. There's a lot of features inside of these IDEs. And that's great, right? If you need that power, if you need that flexibility, by all means, go for that. But the challenge there, of course, is that they're very complex. The learning curve on these is very, very steep. It can take a long time to learn an IDE. And on top of that, typically, they have a fairly high cost associated with them.

4:55Not always-- there are some really good, powerful, free IDEs out there. But most of the really good ones, most of the ones that people use, are going to cost a little bit of money. So by all means, if you want to use an IDE, if you are already familiar with an IDE or your organization already relies on one and has the licenses for it, use that IDE to write Python. You may need to look up how to install some extensions to support Python development, or maybe it supports Python development right out of the box, but it's likely going to be a good choice. It's just going to be a bit more of a complex point to enter into this whole process.

5:27On the flip side, the total opposite of the IDE is the text editor. Now, I'm not just talking about Notepad. I showed you Notepad a moment ago. Notepad is nothing. Notepad allows you to do nothing more than just edit text. I'm talking about these text editors that are kind of robust and kind of a big step up from Notepad. They are typically very lightweight, so they're small to download. They don't take up much memory. They run quickly. They run fast. They're usually a lot easier to use than an IDE. Because they have so many fewer features, their interfaces are a lot less complex.

5:58They cover the basics, really the nitty-gritty details of what you need to write code, but they don't have a whole lot of extra stuff. One of the cool things, though, is the modern text editors that we use a lot are often extensible. And that is true of both of the ones that I've got up here, Sublime Text and Notepad++. Just like the name implies, Notepad++ is meant to be sort of Notepad but on steroids. It's a better version of Windows Notepad. It's available on every major platform as an editor, and it looks a little something like this. Here is that same Python source code open in Notepad++.

6:30And notice two big differences here? Well, one, we've got a whole toolbar full of options up here that do different things, that might do some interesting different stuff. And two, notice that some of the text down here has been colored in. That's important. We call that syntax highlighting. You're going to see that in all of the additional code editing options that I show you here. It's one of the most basic features that a code editor is going to offer and one of the most important. Syntax highlighting helps you understand your code better. So if you're using a code editor, make sure it has syntax highlighting specifically for the Python language. Sublime Text is another one similar to Notepad++.

7:03Notepad++ is free. Sublime Text does have a small fee associated with it, but I would highly recommend it. This is one of my favorite text editors. I use it a lot. Sublime Text looks like this. Again, you can see the syntax highlighting that we saw in the other one-- even more so. There's even more syntax highlighting than there was inside of Notepad++. Sublime Code and Notepad++ both offer extensibility. They both have plugins that can be installed. So they are really, really good choices. I would recommend those both as choices to get started with editing your code. But that's not the one that I want to use in this video series.

7:35In this video series, I want to use something that's, well, kind of in between the two, in between text editors and IDEs. I think they're often referred to as IDEs, but I'm gonna to call them code editors. And there's two major ones that I want to discuss. There's a lot of different options out there in this space, as well. If you haven't figured it out already, there's a lot of code editors in general that you can use in a lot of different ways. It all comes down to personal preference. But the two that I'm going to talk about are Atom and VS Code. And really, I'm just going to focus on VS Code. Atom is a free, lightweight text editor, code editor, similar to Sublime but a little more robust.

8:10This is what an Atom code looks like. Oh, and let's see here. You can find it online at atom.io. This is the download page for it. It's going to run on all the major platforms, just like all the rest of these options that I've shown off. And Atom allows you to browse your code as a sort of project. So I have my folder over here as a project. Here's my code with syntax highlighting built-in. This is just with the default, nothing additional installed or setup. It will allow me to do some interesting different things, like connect up to GitHub for source code control. It's going to have some built-in harnesses for testing, and for running my code, and running my packages.

8:44But by no means is it a full-fledged IDE, like something like NetBeans. It's much simpler than that. The one that I'm going to use, my favorite code editor, is one called VS Code. And VS Code looks like this. I'm going to spend a lot of time here inside of VS Code throughout the rest of this video series on Python, so get used to seeing this interface. Now, VS Code can be downloaded for free. It's also a free piece of software, found here at code.visualstudio.com. And download it for your platform. It runs on Mac, Windows, and Linux. It looks and works the same on all of them.

9:16The installation is largely wizard-based, so I'm not going to walk through that. You need to download the executable, run the executable, and get VS Code installed. Your VS code will not look exactly like mine when you install it. I've gone through some customizations on it. You can watch my videos on installing and setting up VS Code for your development environment here at CBT Nuggets, that walk you through, soup-to-nuts, how I like to configure and set up VS Code to work for me so that it will look like this. But don't worry if it doesn't look like this. The basic installation of VS Code works great. You don't need to worry if that's what yours looks like and you want to keep it that way.

9:47That's perfectly fine, too. This is all just fine-tuning the aesthetics of the software itself. One thing that I do want to do, I do want to show you, is over here, this little option right here is called Extensions. And this is where I install any extensions that I want to install on my Code. Notice right down here in the recommended, it says Python. I've got a Python file open. It's like, hey, you may want to install Python. If you don't have that, you can search up here for Python. Give it a click. And notice that it has 33 million downloads, five stars. This is a popular common Python extension for VS Code.

10:20You're going to want this installed in your VS Code software. You just click that purple Install button and it's done. It says-- what does it say? Some features may not be available until interactive window session is restarted. That's fine. So I've installed the Python extension now. That is now available to me inside of my code. And I can run and execute my Python scripts from right here inside of VS Code. One thing that I would like to note down here in the lower left, it says Python 3.9.2 64-bit. Let me shrink this up so it's on screen for you here.

10:53So if you hover over that, it says c colon backslash Python39 backslash python.exe. If you recall, that is where I installed Python 3.9 in my earlier video. So VS Code was able to automatically find that installation for me. If you wanted to run a different version, you could just click this, and I can go choose different versions of Python that are found in different locations on my computer. For the specific interpretor executable that I want to use, I am, of course, just going to leave it at Python 3.9.2. That is the reason I installed that, because I want to use that. So this code up here, I can run using the key F5, or up here on the menu, F5, Start Debugging.

11:28I want to run the Python file. It's going to launch this inside of a new terminal window that is built right in here into VS Code. So if you recall, earlier, I ran this in a terminal window in Windows. And it said, "What is your name?" That same thing is now happening down here inside of the terminal in VS Code. My name is Ben. How old am I? 42. "Hello Ben. You're old enough to vote in the US." All right. So there you have it. That is my personal preference for code editors for development in Python. VS Code, I think, is a great choice. But if you don't want to use VS Code, you can use Atom, Sublime, Notepad++-- really, any of the options that I mentioned in here are fine, with the exception of Notepad.

12:04Don't use plain Notepad. That's just a bad idea. By using these code editors, you're going to get syntax highlighting. You're going to get all sorts of benefits and features that will help you write good, clean, effective code, and also help you read your code, which is a big part of development, as well as looking at, and reading, and understanding code. So that is what I recommend. By all means, you make your choice, the thing that you feel most comfortable with, the editor that you feel most comfortable with. If you are brand new to programming, I would recommend downloading and starting with VS Code and watching my series on getting VS Code configured and setup on your system.

12:34I hope this has been informative for you, and I'd like to thank you for viewing.

Writing our First Program

0:05OK. Wow, we have covered a lot. We have looked at what a programming language is, and why we need to use a programming language. We have downloaded and installed Python on our system. We've configured our environment variables. We've talked about code editors. You know what I'm ready to do? I'm ready to write our first program. I know. I know. I said earlier that we wrote our first program when we did a little print statement instead of the interactive Python terminal. Actually, I don't think that counts. I think I want to write a piece of code inside of a Python file and execute that script, execute that code with Python.

0:37So let us first make sure that we are completely prepared for what we need. And that means that you should have gone through the earlier videos and accomplished or succeeded at all these tasks. You should have installed Python. You should have chosen your favorite code editor, and downloaded and installed that code editor. And you should add any Python extensions to that code editor that you might need. If you don't have all of this done, if you aren't ready with something like VS Code or Sublime Text to start writing some code, go back and watch those videos and make sure you've understand all that, you've gone through those steps. That's the only way you'll be able to follow along with what we are doing here.

1:10And that is exactly what we need to do now, so that we have this up and running. Let's write some code. I'm here inside of Visual Studio Code. And I have mysourcecode folder open. I did that with File, Open Folder. I chose mysourcecode in C colon. There it is. And you can see there's already that file that I was working with in an earlier video, samplecode1.py. I'm not going to use that. I'm going to do a new file. I will call this firstprogram.py.

1:40Using the .py is very, very helpful for VS Code. That's an indicator to it that it is a Python program. Notice that when I do that, the icon changes to that blue and yellow kind of squirrely thing, the Python icon. So by calling it .py, that tells Visual Studio Code, this is a Python file. Let's write some code. This is going to be a very simple program, but is going to be more interesting than just printing out, hello world. If you want to follow along, you need to follow along very explicitly with what I type in here. So I'm going to say, username = input, and then open parentheses.

2:13And notice, it put the closed parentheses in there for me. That's called autocompletion, a nice feature of an IDE or a code editor. A double quote. And then inside the double quote, I'm going to say, What is your name? And that's it. I'm going to go to the end of line and Enter down. Like I've said in the past, coding is very specific. It's very precise. Those parentheses, those quotes-- those are important. You can't mess those up-- the equals sign. It's important, even though you don't understand what's going on here just yet-- I'm not worried about explaining to you how this code works.

2:45I just want you to type it in and follow along. It is important that you type it in exactly as you see it. And this file will be available in the Supplemental Files to download at cbtnuggets.com, so you can certainly compare what you type compared to what I type, in case you get lost or confused, or something's not working right. Having done that, we now have-- well, you don't need to this just yet, but we have a variable named username that will get populated with what the user types in. I can now print out to the terminal another open parentheses, another double quote, Hello there space, close quote.

3:16But after the close quote, before the close paren, I'm going to do space plus username then my close parentheses, just like that. So now, instead of one line, it's two lines long. I realize it's not a big change. It's not a big update. But you know what? It's a cooler first program than just hello world. It actually has some interaction with the user. Last thing, you need to make sure that you are set up on your Python executable if you want to execute it inside of the Visual Studio Code editor, like I do. Down here, it should say Python 3.9.2 64-bit.

3:47You should hover over it and see the installation for your Python executable. If it doesn't, it's very easy to fix. Just give it a click. Type Enter interpreter path. You can either type the path in directly here, or click Find, and this will allow you to browse your system for the exact interpreter that you want. So if I wanted to run this with Python 3.8, I could change it to Python 3.8 right here. I'm going to leave it at Python 3.9. Open up that. Select python.exe. I have now selected the Python interpreter. The keyboard command F5, or the menu Run, Start Debugging, will execute this code.

4:19It's asking me what I want to run. I can choose the top option here, Debug the currently active Python file. That is absolutely true. That's what I'm using. It will launch a terminal window down here on the bottom half of my screen for me, launch the program, and it asks right away, "What is your name?" My name is Ben. And when I hit Enter, it says, "Hello there Ben." If you want to execute this code outside the confines of VS Code, well, that's easy enough to do. For instance, if I bring up my terminal window here-- this is just my Windows Command Prompt-- here instead of mysourcecode, I've saved that code to firstprogram.py. So I can absolutely say python-- if I spell it right-- firstprogram.py.

4:53This is going to run my code. There it is. "What is your name?" My name is Joe. "Hello there q So we've written and executed our first program, our first Python script. It's saved as a plain text file with a .py extension, but Python can interpret and execute that on our system because we have Python installed and because we know how to run our code. Congratulations. We've done it. It's a small first step, but it is a first step on the journey of Python coding. We have written an interactive piece of software, an interactive piece of code, an application that runs and interacts with the user.

5:23I hope this has been informative for you, and I'd like to thank you for viewing.

Frequently asked questions

What does the Introduction to Programming and Python lesson cover?

This 57-minute lesson explains what programming is and why computers need precise, unambiguous instructions. It compares compiled executables with interpreted Python source code, then walks through installing Python 3 from python.org on Windows, macOS, and Linux, configuring the PATH variable, and choosing a code editor.

Does a team member need prior programming experience before starting this Python lesson?

No. The trainer opens by establishing shared vocabulary so everyone approaches programming from the same mindset, and notes that it is a good place to start even for someone who has never written code. For a Team Lead, that makes it a practical baseline before assigning the rest of the intermediate course.

Why does an introductory Python lesson cover configuring the PATH environment variable?

When multiple Python versions are installed, PATH determines which one runs. The trainer demonstrates a system with Python 3.7 and 3.9 where python --version returned 3.7, then shows how to point PATH at the intended version, and recommends checking the Add Python to PATH option during installation.

Should my team use VS Code or a full IDE for Python?

The lesson compares the two. Full IDEs are powerful, with built-in testing, source control, and library tooling, but they have a steep learning curve. Lightweight editors such as VS Code or Sublime Text are quicker to adopt, and the trainer demonstrates writing code in Visual Studio Code and adding Python extensions.

What can a team member do after completing this lesson?

They can install Python 3 and test commands in the interactive Python terminal. They can also write and run a Python script that stores user input in a variable and prints a greeting. The trainer notes that the script file is available in the Supplemental Files so learners can compare it with what they typed.

How does this lesson fit into the full Python course for an IT team?

It is the starting point of a course that takes about 20 hours per learner and covers syntax, control flow, functions, object-oriented programming, file handling, databases, Pandas, and AWS and Azure SDKs. Training Managers can assign the core programming modules first and then route data, cloud, or database topics by role. CBT Nuggets Playlists and Team Reporting help sequence that rollout and verify progress.

Team training path

Turn this skill into assignable team training

This free skill is a preview of the courses your team can assign, track, and report on with CBT Nuggets.

What's next?

Ready to keep going?

For your team

Bring this training to your team

See how CBT Nuggets helps IT teams close skills gaps, hit compliance targets, and prove training ROI.

Book a Demo
Just need PCAP certification?

Learning on your own? Browse individual plans ($49/month, billed annually) →

Not ready to buy?
with no purchase required. Already have an account?
Book a Demo