Skip to content
CBT Nuggets

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 lesson from Getting Started with Python 3. Preview the IT training 23,000+ organizations trust.

57m 6 Videos 6 Questions

Skill 1 of 10 in Getting Started with Python 3

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?

Verify your team's readiness — Request a Demo to verify practice assessments, completion reporting, and CSV / SCORM exports on the Team plan.

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?

  1. ABytecode
  2. BBinary
  3. CExecutable
  4. DInterpreter

Verify your team's readiness — Request a Demo to verify practice assessments, completion reporting, and CSV / SCORM exports on the Team plan.

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)

  1. AMacOS
  2. BWindows
  3. CLinux
  4. DBeOS
  5. EOS/2

Verify your team's readiness — Request a Demo to verify practice assessments, completion reporting, and CSV / SCORM exports on the Team plan.

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?

Verify your team's readiness — Request a Demo to verify practice assessments, completion reporting, and CSV / SCORM exports on the Team plan.

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?

Verify your team's readiness — Request a Demo to verify practice assessments, completion reporting, and CSV / SCORM exports on the Team plan.

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?

  1. AThe precise syntax matters
  2. BIt's so easy a caveman could do it
  3. CIt was developed in the past decade
  4. DThere's very few effective programming languages

Verify your team's readiness — Request a Demo to verify practice assessments, completion reporting, and CSV / SCORM exports on the Team plan.

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.

0:07You're here today because you want

0:08to learn a little bit of something about programming.

0:11And I want to talk quite a bit about programming itself.

0:14The act of developing programs and applications

0:17for our computers.

0:18Now, you may have an idea of what programming

0:20is, you may have even done some programming and some scripting

0:23in the past, it's certainly a very common thing to have done.

0:25So you may have done that, but even if you haven't, this

0:28is a perfect place to start.

0:29I want to level set exactly what we're

0:31talking about when we talk about programming so that we're all

0:34approaching it from the same mindset, in the same direction.

0:37And we understand the vocabulary that we're using

0:39and why we're doing what we're doing

0:41and really just answer the question initially here,

0:43what the heck is programming?

0:44What in tarnation are we doing?

0:46And I think the answer to that question

0:48is actually relatively straightforward,

0:49although as always with computers,

0:51the devil is in the details.

0:53Programming is just the act of providing a set of instructions

0:57that the computer can run.

0:58The computer can execute-- is the term we often use.

1:01When a computer program runs, we say it's executing.

1:04And all we're doing is saying, hey

1:05computer, this is what I want you to do.

1:09Why is this important?

1:09Well, computers don't know what to do on their own.

1:12They need someone to tell them what

1:13they should be doing, how to respond to different user

1:15interactions, where to get data from,

1:16what to add up or subtract, or when to show the cool graphics.

1:20All of this stuff gets supplied to the computer

1:23by a programmer using something called a programming language.

1:26I think you've probably heard of some programming

1:28languages before in the past.

1:30A programming language is nothing more than a language

1:34that we can use to communicate those instructions

1:36to the computer very concisely and very clearly and very

1:40explicitly.

1:42Now I want to unpack this a little bit.

1:43Why do we need to use these programming languages?

1:46Why do we have to be so explicit and concise?

1:48And the answer to that question is

1:50because, well, one of my favorite phrases and this

1:52could probably be the mantra for this entire set of videos,

1:55computers are dumb.

1:57I know.

1:58You don't think they're dumb, right?

1:59Most people don't.

1:59They're like, computers are amazing.

2:01They can do all those crazy things

2:02I was just talking about it a moment ago, right?

2:04They can calculate pi out to 6,000 digits

2:07in the time it takes you to type in the letters p and i.

2:09They can play amazing graphical video games

2:12with all sorts of crazy physics going on.

2:14They can do an enormous number of things really, really well.

2:18But the simple fact of the matter

2:19is they can only do those things when

2:21they've been instructed to.

2:21Someone had to figure out how to do those first

2:23and tell the computer to do that.

2:25And a lot of those things aren't really all that complex

2:28when it gets right down to it.

2:29I mean sure it can calculate pi up to 6,000 digits.

2:32But so can I?

2:33It just takes me a lot longer.

2:34That means the computer is not necessarily smart.

2:37The computer is just fast.

2:38And that's what you need to understand.

2:40Computers are very, very fast, but they're also not

2:44very smart.

2:45Computers are dumb.

2:46And they don't handle things like ambiguity or uncertainty

2:50or contradictions very well at all.

2:52A computer needs things laid out very explicitly.

2:54A computer wants to know what it's supposed to do,

2:56when it's supposed to do it, and you

2:58need to be as direct and explicit as possible.

3:01If you give some ambiguous instructions to a computer,

3:04well, best case scenario the computer

3:06is going to interpret those instructions in a way

3:09that you did not intend and has some sort

3:10of unintentional consequences, it's

3:12not going to operate the way that you

3:13thought it would operate.

3:14Worst case scenario, it's going to crash.

3:16Right, the whole computer is going to come down.

3:18The system is going to stop.

3:19The operating system is going to stop.

3:20I think you've probably worked on

3:22a computer system in the past that has crashed,

3:24certainly not an uncommon operation, that's

3:25because the computer ran into some instructions

3:27and ran into some code that it didn't understand

3:30how to deal with or how to handle

3:32and it just threw up its hands in the air said,

3:33fine I don't know what to do with this.

3:35I'm just going to give up.

3:36So computers-- yes computers are dumb.

3:39I want you to remember that and keep that in mind.

3:41So how do we communicate instructions

3:43to a dumb computer.

3:45Well, you may be thinking, hey, I speak English.

3:47I can use English, right?

3:48I'm pretty great at communicating instructions

3:50say to my children when I want them to get dressed

3:52and put their shoes on and get ready for school.

3:54I mean I can 4-year-old how to get ready for school.

3:57Surely I can computer how to calculate the pi.

4:00Well, it's not as easy as all that.

4:01Right?

4:02The languages that we use to communicate with each other

4:04and to other people are called the natural languages.

4:07And this is because they have naturally

4:08evolved in the human species.

4:10We're talking about all the language

4:11that we speak English, Mandarin, Russian.

4:13Whatever language you talk, these

4:15are the natural languages.

4:16And natural languages are great at conveying

4:19all of the intricate complexity of human emotion

4:22in our inherent contradictions in all

4:25of these different ambiguous things.

4:26We use not just our language, but our hands,

4:28we use facial expressions.

4:30And all of this combines to make a really powerful communication

4:33platform for people.

4:35But computers don't really deal well with that.

4:37Computers can't read the emotion out of your eyebrows.

4:40Computers cannot understand what your hands moving

4:42in a particular way might mean or how that inflects what it is

4:45you're saying.

4:46No, computers need things very, very explicit.

4:49And I think you've probably run into this before as well.

4:52You've heard of binary right?

4:54Zeros and ones.

4:55Every instruction, every application,

4:57everything that runs on a computer

4:59is ultimately stored in binary and as a bunch of code that

5:03is made up of zeros and ones.

5:05And that is how computers interpret everything.

5:08Why is binary so powerful?

5:10Because binary is unambiguous.

5:12There is no room for ambiguity in binary.

5:14It's either a zero or a one.

5:16It's on or off.

5:16It's true or false.

5:17It's yes or no.

5:18It can't be halfway between true or false.

5:21You can have something that's halfway between 0

5:23and technically you've got 0.5, but the computer,

5:26it's binary code doesn't know how to deal with that.

5:28It's either one thing or the other thing,

5:30which is a very clear cut and very direct and very precise.

5:32And that's very important for computers to do their thing,

5:36for computers to operate.

5:38What's the problem here?

5:39Well, of course people cannot speak binary.

5:42So we think about the gap between these two

5:45things, the natural languages and the binary languages.

5:48Where do people come into play?

5:49I mean, after all, I can't write binary code

5:52and to be perfectly clear nobody does actually

5:54write binary code.

5:55That's not a thing that happens.

5:57Worst case scenario people write something

5:59known as machine language.

6:00But the simple fact of the matter

6:01is binary is too verbose.

6:03It's too long.

6:03It would take thousands of digits just

6:05to express a simple basic instruction like adding

6:08two numbers together.

6:09So we can't write binary.

6:11People cannot write in binary code.

6:13But if people can't write binary and computers

6:15can't understand English, what's the answer?

6:17What's the compromise?

6:19Well, the compromise is what we call a higher order programming

6:22language.

6:22And we are going to talk specifically

6:24in this set of videos about one of them

6:26Python, although there are many programming

6:29languages out there.

6:29I've got a few examples up here in the upper C-Sharp, Java,

6:33Perl, .NET.

6:33You may have heard of some of these, some of them

6:35may be new to you.

6:37There are quite literally hundreds of viable programming

6:39languages out there.

6:40We're going to choose Python for a number of reasons I'll

6:42talk about in another video.

6:44So a programming language like Python is a compromise.

6:47Is a compromise between these two extremes.

6:49Between the natural languages and the preciseness of binary.

6:53It's strict enough for computers.

6:55So we can very explicitly state what

6:57we want to state to the computer, what

6:59we want it to do.

7:00But it's relaxed enough that humans can both understand

7:02it as well as write the code.

7:04A programming language-- a code that you

7:06use to instruct the computer is going to look somewhat legible.

7:10Somewhat readable.

7:11It will look kind of similar to the English language

7:14in this case.

7:14It's going to follow largely the rules of the English language.

7:17We're going to read it top to bottom, individual lines

7:19get read left to right, you'll see words like if and then

7:23and loop that you recognize from the English language

7:26although they have very precise specific meanings.

7:28You'll also see some constructs that

7:29don't make any sense at all.

7:31You'll see colons and parentheses

7:32and curly braces all used in places where you would not

7:35expect them.

7:36So there's going to be a lot of structure and rigidity,

7:38and we're going to have a very limited vocabulary of things

7:41that we can say with our programming language.

7:43So it is not a full fledged natural language.

7:45You couldn't really use a programming language

7:47to communicate between two people.

7:48It compromises between those two.

7:50It comes up with a decent way to make language or code

7:54that humans can read and write but will also

7:56be able to be ultimately interpreted

7:58by computers as a collection of zeros and ones.

8:01So that is what programming is.

8:03And that is ultimately why we use programming languages

8:06to program our computers, because say it with me,

8:08computers are dumb.

8:10They need us to be very precise, very explicit in what

8:14we want them to do.

8:15If we give them ambiguous directions,

8:17if we create some uncertainty, who knows

8:18what's going to happen?

8:19We certainly don't, so we want to avoid that

8:21as much as humanly possible.

8:23I hope this has been informative for you

8:25and I'd like to thank you for viewing.

Compiling Code into Executables

0:05You'd like to start writing some code.

0:08I don't blame you.

0:09I want to start writing code with you.

0:10We are so close.

0:11We're almost ready to go.

0:12But we do need to level set a little bit more.

0:15There is a thread, a loose angle,

0:18that I left a little bit open in my last video--

0:20a question that was unanswered.

0:22And if you didn't notice it, well, that's

0:23OK because I didn't explicitly ask the question.

0:25You would have had to been paying very close attention

0:28to pick up on it.

0:29But let's refresh.

0:30What did I talk about in my last video?

0:32Well, I talked about the fact that computers only

0:34use binary code.

0:36But we need to write in something like a programming

0:38language so that we can understand what we're writing.

0:41And then the computers can interpret it and execute it,

0:44what we meant.

0:45But if we're writing Python code and the computer

0:48needs 1's and 0's, binary code, there's a gap there.

0:51How does my Python code, or how does my C code,

0:54or how does my Java code get converted into binary?

0:57Well, the answer is a separate step,

0:59a process called compiling.

1:02When we compile our software, we take

1:04our source code, which is actually just written

1:06in plain text, just ASCII text-- most source

1:09code can be opened in a software, like, Notepad, right?

1:12It's just plain text file.

1:13And it converts that into a binary executable file.

1:17Let's talk a little bit about what that means.

1:20Imagine you want to feed someone a cake.

1:22Well, you don't have a cake.

1:24What you've got are a bunch of ingredients-- sugar,

1:27eggs flour, milk, whatever is going into the cake.

1:30You can't eat these things.

1:31I can eat these things, right?

1:32I'm not eating spoonfuls of raw flour.

1:34I'm not cracking eggs into my mouth.

1:35I want a cake.

1:36But in order to get a cake, I have

1:38to take my raw ingredients, and I've

1:40got to do some additional steps, right?

1:42I've got to mix them up.

1:43I've got to bake them in the oven.

1:45And then at the end of all that processing, now

1:47I've got a cake, a cake that can actually

1:49be consumed by a person.

1:51Well, I like this analogy.

1:52This is a good analogy for our source code, which

1:55is like our raw ingredients.

1:56That's the code that we are going to write.

1:58Our Python, our C, whatever code we're writing,

2:01is going to be our source code, plain text, inedible

2:04for the computer.

2:05The computer cannot eat that source code.

2:07We have to go through this extra step of compiling before we get

2:10the 1's and 0's, the binary code, which

2:12is also known as an executable.

2:15And you can see this on your computer.

2:17If you have any software installed on your computer,

2:19there is an executable.

2:20For instance, I'm going to bring up my File Explorer in Windows

2:23here.

2:23And let's just look inside of my Microsoft Office folder.

2:26I happen to know where this is.

2:27So I'm going to drill down into the specific location

2:30where it's found.

2:31Look at C Office--

2:32nope, not 15-- 16, right?

2:34Yeah, there it is.

2:35If I scroll down to the Es, I see-- look at this--

2:38EXCEL.EXE.

2:40Application type, the size is 62 megabytes-- a fairly large

2:44binary file.

2:45That file right there, EXCEL.EXE,

2:47is a binary executable.

2:48That is the 0 and 1 instructions that the computer

2:51needs in order to run the Microsoft Excel program.

2:55That's where it's all contained.

2:56That's where the magic is.

2:57And this is true regardless of whether you're

2:59on Windows or Linux or Mac.

3:01There's always a binary executable file

3:03that has to contain all of those instructions.

3:06It's not something you can look at.

3:07If I try to open it up with--

3:09let's see here-- something, like, Notepad,

3:12look at this total gobbledygook garbage.

3:14This is not understandable.

3:15And that's because that EXCEL.EXE is not a text file.

3:19That EXCEL.EXE is a binary executable file.

3:22This is the result of the Microsoft Excel source

3:25code being compiled and being delivered to the end user.

3:29And that's really, at the end of the day, what you

3:31should be thinking about here.

3:32All of these steps prior to the actual cake

3:35is being done by the developers.

3:36It's being done by the person delivering the software.

3:39In the case of Microsoft Excel, that's Microsoft.

3:41They write the source code.

3:42They go through the compilation step.

3:44And they deliver to you, the end user, an executable file.

3:48That is how programming, that is how code, works.

3:51At least that's how it works most of the time.

3:53Now, there are some scenarios where that's

3:56not quite exactly how it works.

3:57And Python is one of those scenarios.

3:59Python-- when you write Python code,

4:01it does not compile all the way to a binary executable.

4:05Python splits up the work a little bit

4:07into a couple of different separate steps.

4:10Now, at the end of the day, we still

4:12have the same basic things.

4:13We still have our source code ingredients written in Python.

4:16And we still have our final cake that is a binary file.

4:19But what we do for Python, as well as other languages,

4:22such as Java or .NET, is we only partially compile it.

4:26We only take it a part of the way

4:28and turn it into something called bytecode.

4:32Now, we won't get too in depth.

4:33But a bytecode file is not binary.

4:36It's not a binary file.

4:37It's not an executable.

4:38A bytecode file is not yet ready to be executed by a computer.

4:42We ship this bytecode file to the end user.

4:45And they have an interpreter installed in their machine that

4:48performs the final execution, the final compilation

4:52of that bytecode into a binary file in real time,

4:55while the file is being executed, while it's being run.

4:57We call this, sometimes, just-in-time execution,

5:00or just-in-time compiling.

5:02This means that our code is not quite finished.

5:06It's not quite baked.

5:07It's parbaked.

5:08If you've ever had a parbaked cake or parbaked cookies

5:11from the bakery, you know that they come partially baked

5:13but not all the way baked.

5:14You need to bring them home, put them in the oven

5:16and finish cooking them.

5:17That's exactly what happens with Python.

5:19So the whole process still has to happen.

5:21We just ship the last final step of that.

5:23We rely on the last final step of the process

5:26to happen at the end user's computer,

5:28the end user's device, when they actually

5:30want to execute the code, when they want to run the program.

5:33So Python code gets converted to bytecode.

5:36This is the process for what we're going through here.

5:39Python code gets converted to bytecode.

5:41The bytecode is delivered to the end user.

5:43And an interpreter, a piece of software

5:45on the end user's machine, finishes running that code.

5:48There's a really important piece that is buried in all of this,

5:51I think, that you need to understand.

5:53And that is the fact that every computer, every device,

5:56every machine that wants to run Python code,

5:58at the end of the day, needs to have

6:00that interpreter installed.

6:02When I compile a C application for saving

6:05Microsoft Windows platform, well, anyone

6:07who has Microsoft Windows installed on their machine,

6:09I know is going to be able to run that application that I

6:11delivered to them.

6:12That's what it needs.

6:13As long as it has Microsoft Windows,

6:14it'll be able to run that.

6:15Not necessarily so with a Python application.

6:18They need not only their operating system,

6:20like, Windows or Mac or whatever it is, they also

6:22need the Python interpreter installed in order

6:25to run my Python code.

6:26That's a really important thing to understand.

6:27It's a really important part of what we're doing here.

6:30And it informs, well, really, it informs the reason

6:32that we do this to begin with.

6:33I mean, after all, what's the point of only doing

6:36this parbaked, partially compiled code

6:38and shipping that to the user?

6:40So let's compare compiling code to an executable

6:43versus bytecode.

6:44When you compile code to an executable,

6:46the executable is absolutely going to run faster.

6:49And it's going to be more efficient in memory usage.

6:51Compiled code, compiled executable,

6:54beats out bytecode on both of those particular notes.

6:56So why do we do it?

6:58Well, because bytecode is platform independent--

7:00it is portable.

7:02It can be delivered to a number of different systems.

7:05The basic idea here is that we have write-once code base

7:12so that we can only manage a single code base

7:15and deliver a single compiled bytecode

7:17executable to all of our different target machines.

7:21Let me expand on this little.

7:22When you compile an executable, say,

7:24in the C++ programming language, if you write an application

7:27in C++, and you compile, let's say, for Microsoft Windows,

7:30let's say you compile it from Microsoft Windows 10.

7:32That's only going to run on Microsoft Windows 10.

7:35Microsoft is good.

7:36It will probably run on Windows 7.

7:38Maybe it will.

7:38Maybe it won't.

7:39It definitely will not run on, say, Macintosh OS.

7:41It will not run on iOS or Android or Linux

7:44or any other platform.

7:45If you want to compile that code for one of those platforms,

7:48you've got to go back and recompile it

7:50with a new target environment, a new target platform.

7:52So you have to deliver different executable files

7:56to different users on different platforms.

7:58And if your code has some instruction for a given

8:00platform that is not supported by another platform--

8:03so I've written some code that works in Windows but not

8:05in macOS--

8:06I can't deliver.

8:07I can't compile that into a macOS executable.

8:10I'm going to have to maintain a separate code base.

8:12Now I have two copies of my source code-- one

8:14for Windows, one for Mac.

8:15Maybe three-- now I need one for Android.

8:17I need one for iOS.

8:18I need all these different copies of my source code.

8:20I have to compile them all independently and separately,

8:22and deliver them independently and separately,

8:25to the appropriate users on the appropriate platforms.

8:28Sometimes that's ideal.

8:29There are certain situations where that's fine,

8:31and you don't mind going through that extra legwork

8:32to get the speed and efficiency gains

8:34that a compiled executable gives you.

8:36But sometimes that's not what you want.

8:37If you don't have a good handle on who your customers are going

8:39to be or what platform they're going to be running on, you can

8:42use something, like, Python or Java or .NET to write your code

8:46one time and one time only-- one single code base,

8:48compiled to one single bytecode.

8:50And you deliver that bytecode to the end user.

8:52You are relying on the interpreter on the end user's

8:55machine, to handle all the complexities

8:57of actually compiling that for the end user's device.

8:59You don't need to worry about it.

9:01If you have some source code that works in Windows and not

9:03in macOS, you deliver it anyways because the compiler is

9:06going to handle not executing that source code.

9:09It will gracefully handle what to do

9:10in that particular scenario.

9:12As a developer, you don't have to maintain separate copies

9:14of your source code.

9:15You don't have to deliver different versions

9:17of your executable depending on your target user's platform.

9:20So you gain a lot of flexibility,

9:21a lot of portability, when you use code

9:24in this way, when you use this method for compiling your code.

9:28So that was all a lot if you're not familiar with compiling

9:30and what we're talking about here.

9:31I talked about a lot of things.

9:33Let me break it down for you one more time before we sign off.

9:36When you write code, you write source code in plain text.

9:38And, in fact, when we write our first Python program,

9:41I'm going to write it in Notepad just to show that off.

9:43Typically you'll use something nicer than Notepad.

9:45But it is just a plain ASCII text file of code,

9:49of instructions, for the computer.

9:50That has to get converted into binary code,

9:52into the 0's and 1's that the computer can execute.

9:55And that is done through a step called compiling.

9:58Most traditional programming languages

9:59get compiled all the way to a binary executable that

10:02is delivered to a target end user's machine for the platform

10:05that they're running, whether it's Windows or Mac or iOS.

10:08Some programming languages, notably, Java, .NET,

10:11and Python, which we are working with here,

10:13only partially compile the code.

10:15They compile it into something called bytecode.

10:17And the end compilation is actually

10:19performed on the end user's machine

10:22while they're executing, while they're

10:23running the application.

10:25They do need an interpreter.

10:26They do need a virtual machine of some sort running

10:29on their computer in order to interpret that bytecode,

10:32In order to run that code.

10:33So you are relying on the end user

10:35already having that support software on their device when

10:38you ship them a piece of, say, code written in the Python

10:41language.

10:42I hope this has been informative for you.

10:43And I'd like to thank you for viewing.

Installing Python 3

0:05All right, I don't know about you,

0:07but I am ready to start hitting the road here.

0:09Let's get started with Python.

0:11And the first thing that we need to do-- well,

0:13we need to install Python itself.

0:15The Python download can be found at python.org.

0:18And we're going to download a package

0:20and walk through the wizard.

0:21I'll do this on both Windows, macOS, as well as Linux.

0:24So you can see it install on all three.

0:26They all largely work the same, but there

0:28are some unique properties for each platform.

0:30So depending on which platform you're using,

0:32you're going to need to follow slightly different installation

0:34instructions.

0:35Now, there's a few different things

0:36included in the package when we download and install Python.

0:40First of all, of course, our Python interpreter.

0:42Recall that we said in our previous video,

0:45you can't run Python code without a Python interpreter

0:48installed.

0:48Unlike a fully compiled executable,

0:51you need a Python interpreter that can actually

0:53read and understand the bytecode that gets delivered

0:55and then in turn execute that on the target machine.

0:58The target machine in this case is going of the our computer.

1:00So the Python interpreter is installed.

1:02There's also something known as an integrated development

1:05environment for Python called IDLE.

1:06This is a very simple IDE.

1:08I'm going to show it briefly in another video,

1:10but I don't think we're really going to use that much.

1:12Certainly, if you want to use IDLE, you're welcome to,

1:14but you don't need to worry too much about it.

1:16Just know that that's an environment where

1:18you can type Python code in, and it

1:20has some shortcuts and useful features

1:21and utilities that will help you write Python code.

1:25The Python installer also has something called pip,

1:27the package installer.

1:28This is how we install additional separate utilities

1:32that are not actually included in the Python 3 downloads.

1:34So there is a whole universe of libraries and updates

1:37and options and features and things that Python themselves

1:40have developed, as well as the wider community.

1:42There's thousands and thousands and thousands of packages

1:45out there that you can download that do things for you.

1:47Pip is going to be the way that you

1:49get a hold of those packages and install them on your system

1:51so that you can use them inside of your Python code.

1:54We'll get the standard libraries installed as well.

1:57So aside from the pip package installer,

1:59there is a host of libraries that

2:01get shipped standard with Python and are installed

2:04with the Python software.

2:05Those will come.

2:06And then lastly, it is going to set up our file and path

2:09associations.

2:10That's a feature I'm going to talk about

2:12in a different video, but that's a really important thing

2:15to understand to set up in your Python installation.

2:19To begin with, I am going to open up python.org and come

2:22over here to Downloads.

2:22And I'm going to download Python.

2:24Well, the current version is 3.9.2.

2:27Note that it cannot be used on Windows 7 or earlier.

2:29So if you are not on Windows, this

2:31should pop up with the appropriate platform for you,

2:34either macOS or Windows.

2:36I'll click Download so I can download this file.

2:39And once it's complete, I will click

2:41it to execute it and go through the installation process.

2:44Now, you can just click this Install Now if you want.

2:46That will install with all the default features.

2:48There's absolutely nothing wrong with that.

2:50The only thing I don't like here is

2:51where it chooses to install the software.

2:53It's buried down here instead of my user profile on Windows.

2:56I'm not a huge fan of that.

2:57I'm going to say customize installation.

2:59I'm going to leave everything the way

3:01it was except for this part right here.

3:03I'm going to change this to C colon backslash Python39.

3:08This is going to install it inside

3:10of the Python39 folder on my root C drive on my computer.

3:13And as I will show you in a minute, there's a lot.

3:17I'll also check Install for all users.

3:18I think that'll be good.

3:20Click Install.

3:21And this will install Python for me.

3:23Very simple and straightforward, not a difficult thing

3:26to do on any of these platforms.

3:28It's pretty streamlined.

3:29The process, it's fairly easy to do.

3:34That took a few minutes to complete, but once it's done,

3:36you get the "Setup was successful."

3:38And Python is now installed on your machine.

3:40I will show you how to check that out in just a moment.

3:43Let's walk through this same process, however, on Macintosh

3:46OS.

3:47Here is my Mac OS desktop, and same thing, I'm at python.org.

3:51If I come over here to Downloads,

3:52notice now it's Download for Mac OS X. Click the link

3:56and let that download.

3:57And once it's done, I will select it in order

4:00to kick off my download.

4:02Now for Mac, I am just going to click through all

4:05of the wizard options.

4:06I don't think there's anything that I'm

4:07really interested in changing, including

4:08the install location-- not something

4:10I need to update on my Macintosh system.

4:13I'm just going to let it install Python 3.9.

4:16Once again, this should just take a second or two.

4:20And there it is.

4:21It's complete.

4:21It's showing me the file.

4:22Notice there's the IDLE application,

4:24that IDE that we talked about, Python documentation,

4:27a launcher, a number of different things here.

4:30We're almost ready to get into it.

4:31Let's take one more quick look at how

4:33I do this in the Ubuntu software, Linux.

4:36Now, unfortunately, Linux is too rich

4:38and varied of an environment for us to really make

4:41a universal installer video.

4:43I'm going to show off how you do it in Ubuntu using the APT

4:46software.

4:46This is a pretty common way to do things.

4:48So it may well work on the version

4:49of Linux, the distribution that you're using.

4:51If it doesn't, you're going to have

4:53to hit your favorite search engine

4:55and look up how to install Python.

4:56It ought to be pretty straightforward, pretty simple.

4:59So from my terminal, I am going to call

5:02apt-add-repository to add a specific repository to my APT.

5:08It's going to be something known as the deadsnakes, which

5:11is a funny name, but that is where the Python application

5:15is installed here.

5:17And once that catalog is installed inside of my package

5:20library, I can now call sudo apt install python3.9.

5:25This will install Python version 3.9 for me.

5:28Get this installed here.

5:30Once this is complete, I can verify at the terminal window

5:34that Python is installed.

5:35Let me show you how to do this quickly in my terminal here.

5:37Then I'll launch up my Windows terminal

5:38and show you a little bit about what we've done.

5:41So there.

5:41It appears to be complete.

5:43I'm going to call python3.9 --version.

5:48And this is going to show me that, yep, it

5:49responded with Python 3.9.2.

5:52I now have that installed.

5:54Let me open this up in Microsoft Windows

5:57and do something similar.

5:59So here I'm at a Command Prompt, a terminal

6:01window in Microsoft Windows.

6:02By the way, you can do the same kind of thing in macOS

6:05as well, if you're familiar with how

6:07to launch the terminal here.

6:08I'm just going to call python --version and see what I get.

6:11I get 3.7.4.

6:13And the reason for that is because of the fact

6:16that I have multiple versions of Python installed.

6:18And my path version currently points to version 3.4.

6:22If I go cd backslash python39, is where I installed it,

6:26take a look at this directory-- yeah, there's python.exe.

6:29So now when I run Python, it's going

6:31to run this local version.

6:33I'll talk about paths in the different local versions

6:35in my next video.

6:36But python --version in here is now Python 3.9.2.

6:41So if I want to execute Python 3.9,

6:43presently I've got to make sure I'm right here

6:45inside of this folder.

6:46I've got a lot of different versions of Python installed,

6:48like I said.

6:49If I go back to 27, I think I have 27 installed here as well.

6:53So I could call python --version 2.7.17.

6:56So like I said, I've got a number of different versions

6:59of Python installed.

7:00You may only have the one.

7:01But if you have multiple versions,

7:03you need to make sure that you either

7:05change into the proper directory or that you set up

7:07your path variable the way I'm going

7:09to show off in my next video.

7:11But here, all I want to do is run Python without --version.

7:14This launches me into something known

7:16as the interactive terminal.

7:18You see those three little arrow brackets there?

7:20In the interactive terminal, I can just

7:22start typing Python commands, and the Python interpreter

7:24will execute them as I type them,

7:27which is actually pretty cool.

7:28It's a neat way to test out quick little bits of code,

7:31which is exactly what we are going to do right here.

7:34If you've got Python installed, you have the correct version,

7:36you ran Python, you have these three little pips right here,

7:39you can do what I'm going to do, which is to say print("Hello

7:41World!") and hit Enter.

7:50And you can see, it just echoed right back to me, Hello World!

7:53OK, yeah, I get it.

7:55That's not especially exciting, but it

7:57is a traditional first program and that

8:00is absolutely a complete and functional Python program.

8:03Print("Hello World!"), that is a Python program.

8:08If you've done this, if you've gotten this far,

8:10you have written your first Python program,

8:12and we have written our first Python program together.

8:15In my next video, I'm going to talk a little bit more

8:17about configuring our environment

8:18and setting up the path, as well as the code

8:21editors that we want to use.

8:22I hope this has been informative for you,

8:24and I'd like to thank you for viewing.

Configuring the PATH variable

0:05I'd like to take a few moments here and dive

0:07into the weeds a little bit on some system

0:09administration, some configuration

0:11for our installation of Python.

0:13And I touched on it briefly in my previous video

0:15where we installed Python, but now

0:17I want to take a moment to really dig into it,

0:19and what it means, and what we saw.

0:21So here's what we're starting with.

0:23Python, when we install it, gets installed

0:25to a specific directory on our computer.

0:28It had a default directory.

0:29I actually overwrote it, if you recall and watched that video

0:32on me installing it.

0:33So I installed Python 3.9 to a specific directory.

0:36But we can only execute the Python interpreter,

0:38the python.exe file, to interpret and run

0:41our Python code if our user context is in that directory.

0:45And I'll show you what I mean by user context in a moment.

0:47We saw this briefly.

0:49When I launched Python --version after installing it

0:52and I was just in my root C folder,

0:55it returned version 3.7, not version 3.9.

0:58And that's because I had both 3.7 and 3.9 installed

1:00in my system.

1:01But specifically, there was something

1:02known as an environment variable that was pointed

1:05towards the Python 3.7 path.

1:08Now, we could have changed this.

1:10In our installation of Python, you

1:12may have noticed that I breezed past this screen.

1:15But during installation, we had this little option here,

1:18Add Python 3.9 to PATH.

1:21I do not check that.

1:22I would probably actually recommend

1:24that you do check that, but I specifically

1:26left it unchecked to put myself in this scenario

1:29so that I could show off exactly what has happened here.

1:32So what that means is that we need

1:33to open up and add Python 3.9 to our environment variables

1:38itself.

1:38I'm going to show you how to do this in Windows.

1:40I'll briefly take a look at it inside of Mac

1:42so that you can understand how it works in bash.

1:44Mac and Linux work largely the same.

1:46Windows is quite a bit different,

1:48although the functionality is the same across all

1:50of these different platforms.

1:51The first thing you're going to do,

1:53if you are on the Microsoft Windows platform,

1:55is open up your Start menu and type in environment variables

1:58to get this particular link up here,

2:00Edit the system environment variables.

2:03When you click that link, it will

2:04launch this particular window right here.

2:06And notice this button right in the bottom,

2:08Environment Variables.

2:10Environment variables are basically

2:12values that are available to the entire environment,

2:14the entire system.

2:15They come in two forms.

2:16You can see them here.

2:18At the top are the user variables, and at the bottom

2:20are the system variables.

2:22Basically, system variables always apply.

2:24User variables only apply to the specific user

2:27that is logged on.

2:28So user variables can change from user to user.

2:31I'm logged on as CBTBen right now.

2:32If a different user logged in, these values

2:35might be different for that user,

2:37whereas these values would all be the same because they

2:39apply to the entire system.

2:41Both of these have a specific variable

2:42that I'm interested in called PATH.

2:45And again, the user variables, if they duplicate up,

2:47will overwrite the PATH of the system variables,

2:50so keep that in mind.

2:52But let's take a look at the PATH variable itself.

2:54The PATH variable contains a number of different directories

2:57on my system and effectively makes the executables

3:00in those available from anywhere.

3:02So notice, Python37 is included right here--

3:06C colon backslash Python37.

3:08Why is that important?

3:09Well, if I come here into my C colon

3:12and I type Python --version, what do I see?

3:16Python 3.7.

3:17I'm not in the Python 3.7 folder right now,

3:19I'm just in the root folder.

3:21But Windows recognized that it went through the script

3:24and it was able to find python.exe

3:26located in the 37 folder.

3:28If I were to remove this from my environment variables,

3:32so that now Python 3.7 is no longer located in there,

3:36check out what happens now if I actually close this and start

3:39up a new one.

3:41So this is a new command prompt.

3:42When I run Python --version now, I get, Python was not found.

3:46It can't see it.

3:47My user context is currently located in the root C colon

3:51folder, which means there is no python.exe file.

3:54I can only run Python if I change my directory

3:58into that folder.

3:59So if I cd backslash into Python39, for instance,

4:03now I can write python --version and get Python 3.9.2.

4:08But if I'm not inside that folder-- for instance,

4:10if I'm in a folder mysourcecode, how about,

4:14there's no Python installation here.

4:16In fact, there's nothing at all in this folder.

4:18I can't run Python from here.

4:19I get-- well, in this case, it tries

4:21to launch the Microsoft Store and install it.

4:22But it does not run the locally installed copy

4:25of this software.

4:26Now, there's a couple of solutions here.

4:28One, I could always just explicitly reference

4:30them using the full path name, so I

4:32can call python39 backslash python, like this,

4:36and this will execute the Python software for me

4:38by explicitly referring to the version that I want to run.

4:41If I change it-- instead of 39, if I go 36--

4:44do I 36 installed?

4:45I don't.

4:46Oh, I have 3.8, I bet. python--

4:48yeah, there's 3.8.2 installed in Python38.

4:50So I can always reference the specific version,

4:52the specific Python executable that I

4:54want to run by putting the full path in.

4:56But you know, that's a lot of typing.

4:58There's a lot of extra typing.

4:59And if you've only got one version of Python installed

5:01and you only ever need to run that one version of Python,

5:04why not just stick it inside of your PATH variable?

5:06Come here to Environment Variables.

5:08I'm going to come down to PATH right here and say Edit.

5:11And let's add a new entry here, C colon backslash Python39

5:16backslash.

5:17I'll say OK, OK.

5:19I do need to restart my Command Prompt.

5:22And I will change directory into mysourcecode again.

5:26There we are.

5:27Now I can run python --version and it comes up with 3.9.2.

5:31Because I added it to the environment variable,

5:33Windows now searches that PATH, finds a Python executable,

5:37and runs it when I try to execute it here.

5:40We can also do something similar inside of other operating

5:43systems, such as Macintosh.

5:44So for instance, from my Macintosh computer here,

5:48if I launch my terminal window--

5:49I have iTerm installed.

5:51I also have a user context.

5:53This launches me instead of my home directory, benjaminfinkel.

5:56And if I want to run Python, I call python --version-- yeah,

6:012.7.7.

6:02That is what's currently pointed towards in my PATH.

6:05How do I know?

6:05I can call echo $PATH, and that shows

6:10me all of the different folders, all the different locations

6:12that are included inside of my PATH variable.

6:15Now, I'm not going to spend a whole lot of time

6:17getting involved in the Linux and macOS PATH

6:21variables that are located in bash.

6:23You can look up Shawn Powers's excellent Linux administration

6:27course.

6:27And there's a video there about environment variables that

6:30covers all of this in depth.

6:32Functionally, it's effectively the same as what I just

6:34showed you inside of Windows.

6:36You need to have the actual location of the Python

6:38executable file inside of your PATH folder

6:41so that it can be run, it can be executed from any location,

6:44regardless of where you are inside of the terminal window.

6:47All this allows us to run Python from our Command Prompt,

6:50from our terminal windows, regardless

6:52of which folder in, regardless of which directory

6:54we're currently located in, so that we can put our source

6:57code in a different directory than the Python interpreter

6:59and so that we can have multiple versions of Python installed

7:02on our system and explicitly know

7:04when we want to run one version versus another.

7:07I hope this has been informative for you,

7:08and I'd like to thank you for viewing.

Choosing a Code Editor

0:05BEN FINKEL: If you have been following along

0:07with these videos, then you should

0:08have downloaded and installed Python on your system,

0:11opened up the Python interactive editor,

0:13and typed in a line of code and see it run.

0:16That's a cool thing to do.

0:17If you did that, give yourself a little applause.

0:19If that's the first code you've ever written,

0:21hey, that's a big step, and I don't mean to diminish it.

0:24But it is only the first step on a very long journey

0:27that is going to involve a lot of different things.

0:29And one of the first things that we wanna change

0:32is we don't want to spend a lot of time inside

0:34of that interactive editor.

0:35In fact, I'm not going to do that at all.

0:37I think you want to get out of the habit right away

0:39of using the interactive editor with Python.

0:42It's great to just hammer out a line of code or two,

0:44and see it run, and see how it works.

0:46But the second you get above more than like two

0:48or three lines of code, it's no longer really

0:50a useful interface to be working in.

0:52Instead, what you prefer to be doing

0:54is writing source code instead of a source code file,

0:57and then saving that file to your file system.

0:59Now, if you'll recall, I've mentioned a number of times

1:01during the series that source code is saved as plain ASCII

1:05text and saved as a plain ASCII text file on your file system.

1:09And this has a couple of different implications .

1:12The one that I've been talking about

1:13is the fact that source code files need to be compiled,

1:16either to bytecode or all the way to an executable,

1:18before they can actually be executed

1:20on an end user's system.

1:22But it also means that they're kind of universally portable.

1:25ASCII text, if you're unfamiliar,

1:27is just a plain basic text format that computers use.

1:29If you use Notepad in Windows, or I

1:31think it's called TextPad inside of macOS--

1:34these are the types of files that those file editors edit.

1:38It's just plain text.

1:39And if you create a source code file, it's saved as ASCII text.

1:43While not technically universally portable,

1:45it's, in practice, universally portable,

1:47because almost every system out there--

1:49every device, whether it's a tablet, a phone, a laptop,

1:51a desktop, whatever it is, cars and washing machines,

1:54anything that has a computer in it

1:56can probably read a text file.

1:58And that is true of your source code, as well.

2:00And what that means is that we could write our source

2:02code, if we wanted to, in something as simple as Notepad.

2:06You know Notepad, right?

2:07It's the basic editor that is built inside of Windows.

2:10It looks something like this.

2:12I got it on screen here.

2:13This is a Notepad editor.

2:14And yeah, actually, this is a functional Python program

2:17inside of Notepad.

2:18Don't worry about what this.

2:19Does we'll talk about it in a little bit.

2:21But the point is you could write your code inside of Notepad.

2:24I've done that exactly right here.

2:25I have this text written out, saved as samplecode1.py.

2:30I'm going to open up my command line,

2:31and inside of mysourcecode, I believe

2:33that's where I saved that file.

2:34Yep, samplecode1.py.

2:35I'm going to say python samplecode1.py.

2:39This is going to execute my Python interpreter,

2:42passing in that file.

2:43So instead of working in the interactive interface

2:46for my Python interpreter, I have code written to

2:50and saved to a file, and it's going

2:51to execute all of the code inside of that file for me.

2:54So we will click Enter here.

2:56"What is your name?"

2:57Well, my name is Ben.

2:58"How old am I?"

2:59Well, at the time of this writing, I'm 42.

3:01It says, "Hello Ben.

3:02You're old enough to vote in the US!"

3:03Hey, I am old enough to vote in the US.

3:05That's true.

3:06Let's test out this program.

3:07I'm going to run it one more time.

3:08"What is your name?"

3:09My name will be Dolly.

3:10"And how old are you?"

3:11What if Dolly is 17?

3:13"Hello Dolly.

3:14Wait a few more years before you can vote in the US."

3:16That's absolutely true.

3:17You can only vote in the US once you're 18 years old.

3:20So this code, this program was written here in Notepad.

3:22And yeah, OK, technically, yes, you can write your code,

3:26you can write your software in Notepad.

3:28I don't recommend that, either.

3:29I don't recommend it any more than I recommend

3:31using the interactive interface that comes with Python itself,

3:34because while yes, you can edit the actual text of your code,

3:38Notepad offers exactly zero additional features, zero

3:41support to help you write better code,

3:43or to help you understand the code that you're writing,

3:45or to help you navigate, and organize,

3:46and architect your code.

3:48There's a lot of benefits to using

3:50other tools, additional tools, for writing our code.

3:55So some of those tools are known as IDEs--

3:58Integrated Development Environments.

4:00You may have heard of these.

4:01They're pretty popular.

4:02There's a lot of them out there.

4:04This is going to be things like Visual Studio, Eclipse,

4:08NetBeans.

4:08There's a lot of different IDEs out there.

4:10And IDEs are these really big, robust, complex but powerful,

4:15feature-rich tools.

4:16They allow you to do a lot.

4:18They are really designed and built from the ground up

4:20to write and architect large-scale enterprise

4:23applications and software.

4:25They will have built in harnesses for testing,

4:27for source code control, for bringing in libraries,

4:31for linking in different types of code

4:33and different types of software, even things

4:35like navigating databases.

4:36There's a lot of features inside of these IDEs.

4:38And that's great, right?

4:39If you need that power, if you need that flexibility,

4:42by all means, go for that.

4:43But the challenge there, of course,

4:44is that they're very complex.

4:46The learning curve on these is very, very steep.

4:48It can take a long time to learn an IDE.

4:50And on top of that, typically, they

4:53have a fairly high cost associated with them.

4:55Not always-- there are some really good,

4:57powerful, free IDEs out there.

4:58But most of the really good ones, most of the ones

5:00that people use, are going to cost a little bit of money.

5:04So by all means, if you want to use an IDE,

5:07if you are already familiar with an IDE

5:09or your organization already relies on one

5:10and has the licenses for it, use that IDE to write Python.

5:13You may need to look up how to install

5:15some extensions to support Python development,

5:17or maybe it supports Python development right out

5:19of the box, but it's likely going to be a good choice.

5:22It's just going to be a bit more of a complex point

5:24to enter into this whole process.

5:27On the flip side, the total opposite of the IDE

5:30is the text editor.

5:31Now, I'm not just talking about Notepad.

5:33I showed you Notepad a moment ago.

5:35Notepad is nothing.

5:36Notepad allows you to do nothing more than just edit text.

5:39I'm talking about these text editors that are kind of robust

5:43and kind of a big step up from Notepad.

5:45They are typically very lightweight,

5:47so they're small to download.

5:48They don't take up much memory.

5:50They run quickly.

5:50They run fast.

5:51They're usually a lot easier to use than an IDE.

5:54Because they have so many fewer features,

5:56their interfaces are a lot less complex.

5:58They cover the basics, really the nitty-gritty details

6:00of what you need to write code, but they don't have

6:03a whole lot of extra stuff.

6:04One of the cool things, though, is the modern text editors

6:07that we use a lot are often extensible.

6:09And that is true of both of the ones that I've got up here,

6:11Sublime Text and Notepad++.

6:14Just like the name implies, Notepad++ is meant to be sort

6:18of Notepad but on steroids.

6:19It's a better version of Windows Notepad.

6:21It's available on every major platform as an editor,

6:24and it looks a little something like this.

6:26Here is that same Python source code open in Notepad++.

6:30And notice two big differences here?

6:31Well, one, we've got a whole toolbar full of options

6:34up here that do different things, that

6:35might do some interesting different stuff.

6:37And two, notice that some of the text

6:39down here has been colored in.

6:41That's important.

6:42We call that syntax highlighting.

6:43You're going to see that in all of the additional code editing

6:45options that I show you here.

6:47It's one of the most basic features that a code

6:48editor is going to offer and one of the most important.

6:51Syntax highlighting helps you understand your code better.

6:53So if you're using a code editor,

6:55make sure it has syntax highlighting specifically

6:57for the Python language.

6:59Sublime Text is another one similar to Notepad++.

7:03Notepad++ is free.

7:04Sublime Text does have a small fee associated with it,

7:07but I would highly recommend it.

7:08This is one of my favorite text editors.

7:10I use it a lot.

7:11Sublime Text looks like this.

7:12Again, you can see the syntax highlighting

7:14that we saw in the other one-- even more so.

7:17There's even more syntax highlighting than there was

7:19inside of Notepad++.

7:21Sublime Code and Notepad++ both offer extensibility.

7:24They both have plugins that can be installed.

7:26So they are really, really good choices.

7:28I would recommend those both as choices

7:30to get started with editing your code.

7:33But that's not the one that I want

7:34to use in this video series.

7:35In this video series, I want to use something that's,

7:38well, kind of in between the two,

7:40in between text editors and IDEs.

7:42I think they're often referred to as IDEs,

7:44but I'm gonna to call them code editors.

7:46And there's two major ones that I want to discuss.

7:49There's a lot of different options

7:50out there in this space, as well.

7:52If you haven't figured it out already,

7:53there's a lot of code editors in general

7:55that you can use in a lot of different ways.

7:56It all comes down to personal preference.

7:58But the two that I'm going to talk about

8:00are Atom and VS Code.

8:01And really, I'm just going to focus on VS Code.

8:04Atom is a free, lightweight text editor, code editor,

8:07similar to Sublime but a little more robust.

8:10This is what an Atom code looks like.

8:12Oh, and let's see here.

8:13You can find it online at atom.io.

8:16This is the download page for it.

8:17It's going to run on all the major platforms,

8:19just like all the rest of these options that I've shown off.

8:22And Atom allows you to browse your code as a sort of project.

8:25So I have my folder over here as a project.

8:28Here's my code with syntax highlighting built-in.

8:30This is just with the default, nothing additional installed

8:33or setup.

8:34It will allow me to do some interesting different things,

8:36like connect up to GitHub for source code control.

8:39It's going to have some built-in harnesses

8:41for testing, and for running my code, and running my packages.

8:44But by no means is it a full-fledged IDE,

8:47like something like NetBeans.

8:48It's much simpler than that.

8:50The one that I'm going to use, my favorite code editor,

8:53is one called VS Code.

8:54And VS Code looks like this.

8:56I'm going to spend a lot of time here inside of VS

8:58Code throughout the rest of this video series on Python,

9:01so get used to seeing this interface.

9:03Now, VS Code can be downloaded for free.

9:05It's also a free piece of software, found here

9:08at code.visualstudio.com.

9:10And download it for your platform.

9:11It runs on Mac, Windows, and Linux.

9:13It looks and works the same on all of them.

9:16The installation is largely wizard-based,

9:18so I'm not going to walk through that.

9:19You need to download the executable, run the executable,

9:22and get VS Code installed.

9:24Your VS code will not look exactly like mine

9:26when you install it.

9:27I've gone through some customizations on it.

9:29You can watch my videos on installing and setting up

9:32VS Code for your development environment

9:33here at CBT Nuggets, that walk you through, soup-to-nuts,

9:36how I like to configure and set up VS Code to work for me so

9:40that it will look like this.

9:41But don't worry if it doesn't look like this.

9:42The basic installation of VS Code works great.

9:44You don't need to worry if that's what yours looks like

9:46and you want to keep it that way.

9:47That's perfectly fine, too.

9:48This is all just fine-tuning the aesthetics of the software

9:51itself.

9:51One thing that I do want to do, I do want to show you,

9:54is over here, this little option right

9:56here is called Extensions.

9:57And this is where I install any extensions that I

10:00want to install on my Code.

10:02Notice right down here in the recommended, it says Python.

10:04I've got a Python file open.

10:05It's like, hey, you may want to install Python.

10:07If you don't have that, you can search up here for Python.

10:11Give it a click.

10:12And notice that it has 33 million downloads, five stars.

10:15This is a popular common Python extension for VS Code.

10:20You're going to want this installed in your VS Code

10:22software.

10:22You just click that purple Install button and it's done.

10:25It says-- what does it say?

10:27Some features may not be available

10:28until interactive window session is restarted.

10:31That's fine.

10:32So I've installed the Python extension now.

10:33That is now available to me inside of my code.

10:36And I can run and execute my Python scripts

10:40from right here inside of VS Code.

10:44One thing that I would like to note down here

10:46in the lower left, it says Python 3.9.2 64-bit.

10:50Let me shrink this up so it's on screen for you here.

10:53So if you hover over that, it says

10:54c colon backslash Python39 backslash python.exe.

10:58If you recall, that is where I installed

10:59Python 3.9 in my earlier video.

11:02So VS Code was able to automatically find

11:05that installation for me.

11:06If you wanted to run a different version,

11:07you could just click this, and I can

11:09go choose different versions of Python

11:11that are found in different locations on my computer.

11:13For the specific interpretor executable that I want to use,

11:16I am, of course, just going to leave it at Python 3.9.2.

11:19That is the reason I installed that,

11:21because I want to use that.

11:22So this code up here, I can run using the key F5, or up here

11:26on the menu, F5, Start Debugging.

11:28I want to run the Python file.

11:30It's going to launch this inside of a new terminal

11:32window that is built right in here into VS Code.

11:35So if you recall, earlier, I ran this in a terminal window

11:38in Windows.

11:38And it said, "What is your name?"

11:40That same thing is now happening down here inside

11:42of the terminal in VS Code.

11:43My name is Ben.

11:44How old am I?

11:4542.

11:45"Hello Ben.

11:46You're old enough to vote in the US."

11:48All right.

11:48So there you have it.

11:49That is my personal preference for code editors

11:52for development in Python.

11:54VS Code, I think, is a great choice.

11:56But if you don't want to use VS Code, you can use Atom,

11:58Sublime, Notepad++-- really, any of the options that I mentioned

12:01in here are fine, with the exception of Notepad.

12:04Don't use plain Notepad.

12:05That's just a bad idea.

12:06By using these code editors, you're

12:08going to get syntax highlighting.

12:09You're going to get all sorts of benefits and features that

12:12will help you write good, clean, effective code,

12:14and also help you read your code, which

12:16is a big part of development, as well

12:18as looking at, and reading, and understanding code.

12:20So that is what I recommend.

12:22By all means, you make your choice,

12:23the thing that you feel most comfortable with,

12:25the editor that you feel most comfortable with.

12:26If you are brand new to programming,

12:28I would recommend downloading and starting with VS Code

12:30and watching my series on getting VS Code configured

12:33and setup on your system.

12:34I hope this has been informative for you,

12:36and I'd like to thank you for viewing.

Writing our First Program

0:05OK.

0:06Wow, we have covered a lot.

0:07We have looked at what a programming language is,

0:10and why we need to use a programming language.

0:12We have downloaded and installed Python on our system.

0:15We've configured our environment variables.

0:17We've talked about code editors.

0:19You know what I'm ready to do?

0:20I'm ready to write our first program.

0:22I know.

0:23I know.

0:23I said earlier that we wrote our first program

0:25when we did a little print statement instead

0:27of the interactive Python terminal.

0:28Actually, I don't think that counts.

0:30I think I want to write a piece of code inside of a Python file

0:34and execute that script, execute that code with Python.

0:37So let us first make sure that we are completely

0:40prepared for what we need.

0:41And that means that you should have gone through the earlier

0:43videos and accomplished or succeeded at all these tasks.

0:46You should have installed Python.

0:48You should have chosen your favorite code editor,

0:50and downloaded and installed that code editor.

0:53And you should add any Python extensions to that code editor

0:56that you might need.

0:57If you don't have all of this done,

0:58if you aren't ready with something

1:00like VS Code or Sublime Text to start writing some code,

1:03go back and watch those videos and make

1:04sure you've understand all that, you've

1:06gone through those steps.

1:07That's the only way you'll be able to follow along

1:09with what we are doing here.

1:10And that is exactly what we need to do now,

1:12so that we have this up and running.

1:14Let's write some code.

1:16I'm here inside of Visual Studio Code.

1:19And I have mysourcecode folder open.

1:21I did that with File, Open Folder.

1:23I chose mysourcecode in C colon.

1:27There it is.

1:27And you can see there's already that file

1:29that I was working with in an earlier video, samplecode1.py.

1:33I'm not going to use that.

1:34I'm going to do a new file.

1:36I will call this firstprogram.py.

1:40Using the .py is very, very helpful for VS Code.

1:43That's an indicator to it that it is a Python program.

1:46Notice that when I do that, the icon

1:48changes to that blue and yellow kind of squirrely thing,

1:50the Python icon.

1:52So by calling it .py, that tells Visual Studio Code,

1:55this is a Python file.

1:57Let's write some code.

1:58This is going to be a very simple program,

2:00but is going to be more interesting than just printing

2:02out, hello world.

2:03If you want to follow along, you need

2:05to follow along very explicitly with what I type in here.

2:08So I'm going to say, username = input,

2:12and then open parentheses.

2:13And notice, it put the closed parentheses in there for me.

2:16That's called autocompletion, a nice feature of an IDE

2:19or a code editor.

2:21A double quote.

2:21And then inside the double quote, I'm going to say,

2:23What is your name?

2:27And that's it.

2:28I'm going to go to the end of line and Enter down.

2:31Like I've said in the past, coding is very specific.

2:34It's very precise.

2:35Those parentheses, those quotes--

2:37those are important.

2:38You can't mess those up-- the equals sign.

2:39It's important, even though you don't understand

2:41what's going on here just yet--

2:43I'm not worried about explaining to you how this code works.

2:45I just want you to type it in and follow along.

2:47It is important that you type it in exactly as you see it.

2:49And this file will be available in the Supplemental Files

2:52to download at cbtnuggets.com, so you can certainly

2:55compare what you type compared to what I type, in case you get

2:58lost or confused, or something's not working right.

3:00Having done that, we now have-- well,

3:02you don't need to this just yet, but we have a variable named

3:05username that will get populated with what the user types in.

3:07I can now print out to the terminal

3:10another open parentheses, another double quote,

3:13Hello there space, close quote.

3:16But after the close quote, before the close paren,

3:18I'm going to do space plus username

3:22then my close parentheses, just like that.

3:25So now, instead of one line, it's two lines long.

3:27I realize it's not a big change.

3:28It's not a big update.

3:29But you know what?

3:30It's a cooler first program than just hello world.

3:32It actually has some interaction with the user.

3:35Last thing, you need to make sure

3:36that you are set up on your Python executable

3:39if you want to execute it inside of the Visual Studio Code

3:42editor, like I do.

3:43Down here, it should say Python 3.9.2 64-bit.

3:47You should hover over it and see the installation

3:49for your Python executable.

3:50If it doesn't, it's very easy to fix.

3:52Just give it a click.

3:54Type Enter interpreter path.

3:55You can either type the path in directly here, or click Find,

3:58and this will allow you to browse

3:59your system for the exact interpreter that you want.

4:02So if I wanted to run this with Python 3.8,

4:03I could change it to Python 3.8 right here.

4:06I'm going to leave it at Python 3.9.

4:07Open up that.

4:08Select python.exe.

4:10I have now selected the Python interpreter.

4:13The keyboard command F5, or the menu Run, Start Debugging,

4:17will execute this code.

4:19It's asking me what I want to run.

4:20I can choose the top option here,

4:22Debug the currently active Python file.

4:23That is absolutely true.

4:24That's what I'm using.

4:25It will launch a terminal window down here

4:27on the bottom half of my screen for me, launch the program,

4:30and it asks right away, "What is your name?"

4:32My name is Ben.

4:33And when I hit Enter, it says, "Hello there Ben."

4:36If you want to execute this code outside the confines of VS

4:38Code, well, that's easy enough to do.

4:40For instance, if I bring up my terminal window here--

4:42this is just my Windows Command Prompt--

4:43here instead of mysourcecode, I've

4:45saved that code to firstprogram.py.

4:47So I can absolutely say python--

4:50if I spell it right--

4:51firstprogram.py.

4:53This is going to run my code.

4:54There it is.

4:54"What is your name?"

4:55My name is Joe.

4:55"Hello there q

4:57So we've written and executed our first program,

5:00our first Python script.

5:01It's saved as a plain text file with a .py extension,

5:04but Python can interpret and execute that on our system

5:07because we have Python installed and because we know how to run

5:09our code.

5:10Congratulations.

5:11We've done it.

5:12It's a small first step, but it is

5:14a first step on the journey of Python coding.

5:16We have written an interactive piece of software,

5:19an interactive piece of code, an application that runs

5:22and interacts with the user.

5:23I hope this has been informative for you,

5:25and I'd like to thank you for viewing.

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.

Request a Demo

Just need Getting Started with Python 3? Enroll from $300/yr (10 skills)

Request a Demo