Focus video player for keyboard shortcuts
Auto
- 720p
- 540p
- 360p
1.00x
cc
- 0.50x
- 0.75x
- 1.00x
- 1.25x
- 1.50x
- 1.75x
- 2.00x
We hope you enjoyed this lesson.
Cool lesson, huh? Share it with your friends
About this lesson
Let's create our first program.
Quick reference
First Program
In this lesson we'll create our first program.
When to use
This is the first program all coders create.
Instructions
Our first program will be Hello World!
print("Hello World!")
To run the program from the terminal type:
python hello.py
Hints & tips
- Hello World is usually the first program coders learn!
- print("Hello World!")
- All Python files end in .py
- 00:04 Okay, so we've installed all the things,
- 00:06 now it's time to start playing around with this stuff and actually using it.
- 00:09 So head over to your Windows start menu and type in git bash,
- 00:13 it's just G-I-T B-A-S-H.
- 00:15 And the git bash terminal will pop up, go ahead and click it and
- 00:18 this is what you should see.
- 00:19 Mine says flatplanet@flatplanet-PC, that's the name of my computer,
- 00:23 that's my username,
- 00:24 yours will be different obviously based on whatever your username is.
- 00:28 No, I don't think the world is flat I just find it hilarious that some people do so
- 00:31 I named my computer that.
- 00:33 You can type in pwd to see which directory you're in and we're in c/users/flatplanet,
- 00:38 again this will be different based on whatever your computer is called.
- 00:42 So what we need to do now is create a directory where we
- 00:45 can hold all the Python files we're going to create through this course.
- 00:48 So to do that you just type mkdir, and
- 00:52 that command is the same whether you're on a Windows or Mac computer.
- 00:56 Now where do we want to put this?
- 00:57 We could put it on /c/, and then let's call this directory python-course,
- 01:02 you can call it anything you want, but we're creating a Python course.
- 01:06 Now if you're on a Mac or Linux, obviously you're not going to type in C because
- 01:10 Mac and Linux don't have C drives, they have something else.
- 01:13 Save that wherever you want on your Mac or
- 01:14 Linux doesn't matter at all just make a note of where you saved it.
- 01:17 So that's pretty much all we need to do to make a directory.
- 01:20 Now we need to move into that directory and to do that, we do cd, change
- 01:25 directory, and just type in the name of the directory again, so python-course.
- 01:31 And when you do, you see, boom, it shows we're in fact in that directory or
- 01:35 we could type in pwd again to see, yep, we're in that directory.
- 01:39 And we could type ls to list the stuff in this directory and
- 01:42 you notice there's nothing in there, so, so far so good.
- 01:45 So let's clear the screen here, so now head over to your Windows start menu and
- 01:49 type in Sublime, and this should pop up, this is the Sublime text editor.
- 01:53 First things first head over to project and click, Add Folder to Project, and
- 01:57 just navigate through your C drive and find that directory we just created.
- 02:02 So it is see, python course there it is, click it once to highlight it and
- 02:09 then click the Select Folder button and you see, boom, it pops right up.
- 02:13 Let's go ahead and create a file right now and let's just click,
- 02:17 File Save As, and again, navigate to that Python course directory.
- 02:22 We're already in that directory but if you weren't for some reason just go to C and
- 02:26 then search for python course, there it is.
- 02:30 Now let's name this file, hello.py and
- 02:34 all Python files end in .py, that's how our computer knows they're Python files.
- 02:39 So if we hit Enter, you notice it pops right up here so we can close this here
- 02:43 and then if we want to open it again, we just click it right there.
- 02:46 So now throughout this course all of our files will be listed on the left hand side
- 02:49 here, very nice.
- 02:50 So let's write our first Python program, so let's type in print and
- 02:54 in parentheses and in quotation marks, and let's just type in, Hello World, right?
- 02:59 So go ahead and hit Ctrl + S on your keyboard, Cmd + S if you're on a Mac
- 03:03 to save this file, or you can come over here this file and save and that's it.
- 03:08 We're going to talk about this program more in the next video get into exactly
- 03:11 what this is but for now, let's just go ahead and run the file.
- 03:14 So head back over to our terminal, make sure you're in that directory and
- 03:19 type in, python, and then the name of the file, so it's, hello.py, and
- 03:23 this is how you run all python programs.
- 03:26 You type python and then the name of the file and
- 03:28 you see, boom, Hello world it prints right to the screen and that worked.
- 03:32 Now, if you were in a different directory than our python-course,
- 03:37 remember we added Python to pass, so we can run this from anywhere.
- 03:41 You would just do the same thing Python, you just be explicit, type in
- 03:45 /c/python-course/hello.py, same thing, Hello world.
- 03:50 We're already in that directory, so we don't have to do that every time we can
- 03:54 just type in python, and then the name of the file.
- 03:56 So congratulations, you've written and run your very first python program.
- 04:00 This is the first program that all coders do, it's always the
- 04:04 Hello World program and very very simple.
- 04:06 Like I said we're going to talk about what this is and
- 04:09 what's going on in this file and all that good stuff in the next video.
- 04:12 I just wanted to kind of get us running and do something in the terminal and
- 04:16 in the Sublime Text Editor, so you see how those work.
- 04:20 So very, very cool and it's just that easy to start doing Python.
- 04:24 In the next video, we'll go ahead and start to talk more about this program,
- 04:27 explain what some of these things are.
- 04:29 And we're going to also talk about comments in the next video and
- 04:35 that'll be coming right up.
Lesson notes are only available for subscribers.