The First Thing You See: Getting Started With Hello World

show more Getting started with "Hello World" provides you with in-depth training on Developer. Taught by Bill Weinman as part of the Python 3 Essential Training show less
please wait ...

Getting started with "Hello World"

As we start the Python Quick Start, we're going to use the traditional "Hello, World!" program. And purpose of "Hello, World!" is not an exercise to find the simplest form of code in a particular language, or anything like that. It's actually to learn about the development environment, to learn about what we call the development cycle: what it takes to edit, and to test, and to change, and to test and to run code in a particular environment. And so for this purpose we use the simplest form of a program itself, so that that can get out of the way and then we can focus on the environment.

In this case, I've this up here on the screen in Eclipse. And this is Eclipse using Pydev, which is a Python development environment that runs inside of Eclipse. Eclipse is an integrated development environment originally written for developing in Java, but it has plug- ins for a lot of different languages. And Pydev is actually a pretty good plug-in for the Python language. And so, we'll be using this throughout this course. You do not have to use Eclipse, and if you have some other development environment that you prefer, or you just want to use an editor and a command line, that's perfectly fine.

You can do all of the exercises; you do not need to use Eclipse. The reason that I'm using Eclipse is because it's convenient for the purpose of teaching. I've got everything that I need right up here on the screen. I can run code, I get the results of code, and it works well for the purpose of teaching, but you don't need to use it for your development work. And you do not need to use it to follow along in the exercises. In Eclipse, if I want to run this Hello, World!, I simply click on this Run button up here, and it'll ask me, How I want to run it? and I'm going to select Python Run.

I only need to do this the first time I run a script. So I'm going to say OK. And here we have the result down here: "Hello, World!" If I were running this in another environment and I actually have this script loaded up here on a Unix Server - this is my Unix Server - there is the script, you see it's exactly the same. And if run it I say ./, and it runs it. An important part of this is this shebang line.

If we look here in Eclipse, we see this shebang line here. In many environments, mostly Unix- based environments, but this includes Macintosh and it includes many, many web servers that are running Unix-based operating systems, like Linux or PSD, this shebang line is actually very important. It's called a shebang line because it's starts with a hash and then has an exclamation mark, which is sometimes called a bang. And then after that it has the path to the interpreter that will be used to run the script.

When the script is executed and the shell sees it, it will look here for the interpreter and then use that to run the script. So sometimes you'll see a bash up here, or Perl, or something like that. And all that's doing is it's telling the shell to use that interpreter to run whatever script is there. For Python, it's going to be something like this. It might be #!/usr/bin/python3. It might be #!/usr/local/bin/python3. It might be #!/usr/bin/env python3, something like that.

In this case, I'm using #!/usr/bin/python3 because I know that, that works in the environments that I'm using. And if it doesn't, then I'll make a symbolic link or something and make it work. So if you're running this on a Unix-based operating system, you'll want to do ls -l and look at the file permissions, and make sure that it has executable permissions. If it doesn't, you can make it executable by typing chmod, or as we pronounce it chmod 755, which makes it editable and executable for your user ID, and then the name of the file.

And that will make it executable. And then you can execute it with ./ or however it is that you do that on your system. So that is the development environment that we will be using. For the most part, we're going to using Eclipse. And so we'll be running scripts like this. Save it and Run it. It'll run here in the Console. So you're going to want to take the opportunity, using this "Hello, World!" script, to learn about the development cycle and whatever environment you're using, especially if it's not Eclipse, to follow along with the exercises in this course.

Getting started with "Hello World"
Video duration: 4m 43s 6h 36m Beginner


Getting started with "Hello World" provides you with in-depth training on Developer. Taught by Bill Weinman as part of the Python 3 Essential Training

Developer Web
please wait ...