Well done!
You have completed Hello Python!
You have completed Hello Python!
Jump into a workspace and learn how to create and run a Python file.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upOpen up the workspace attached to this video, and follow along with me. 0:00 You can find it in the bottom right-hand corner, fantastic. 0:07 Your workspace currently has one file called app.py. 0:09 Files that hold Python code end in the .py extension. 0:14 You can click on this file to open it. 0:19 This top section here is your file, and the bottom section is the console. 0:22 The console is where we'll be able to see our Python code in action, 0:28 let's get coding. 0:33 Inside of app.py, 0:35 we're going to create a variable called name that will hold your name. 0:36 In Python, you don't need to write anything special to start a variable. 0:41 You just write name =, which is the syntax to create 0:45 your first variable, then add your name. 0:49 We'll want this to be a string, so 0:53 you'll need either double-quotes or single-quotes. 0:57 Either is fine, then add your name between the quotes. 1:02 One great thing about this variable is that the name is descriptive. 1:08 If this variable was called name and it held 5, it wouldn't make 1:12 a lot of sense, and could cause problems in your code later on. 1:17 Naming things descriptively in your code is an excellent habit to get into. 1:22 Okay, so we have a variable, awesome. 1:29 But what can you do with it, it's just sitting there. 1:31 As I've said before, you interact with Python code in the console. 1:37 So let's add a print statement after our variable. 1:42 Print() is a function that allows us to send messages to the console, 1:49 to see them down here. 1:55 Inside of this print statement, let's write a string, 1:57 My name is, this will print 2:03 this message to the console. 2:08 You can also print a variable, 2:13 print(name). 2:18 I want you to think about what messages will be printed 2:21 to the console when this file is run, so let's do that now. 2:24 Save the file, Ctrl or Cmd+S. 2:28 In the console, type python app.py. 2:32 This is how you tell Python to run a file, here, app.py. 2:37 There is also a fun shortcut. 2:42 If you type python and then the beginning of the filename, you can hit 2:43 the Tab button and it will automatically complete the filename for you. 2:48 This can speed things up a bit. 2:53 Okay, hit Enter, and the file will run. 2:55 You'll know when the program is complete when the console prompt is shown again. 3:00 In the console, I see two messages, My name is and Megan. 3:06 The first message, we created inside of our print statement. 3:12 The second message came from our variable, which is holding our name. 3:18 Python saw this variable and then went to find what that 3:27 variable was holding, and then printed that message out. 3:32 What happens if we switch these print statements around? 3:37 Well, let's do it and see. 3:41 Programing is all about trying things out and seeing what happens. 3:43 So don't be afraid to play around, all great programmers do. 3:46 Don't forget to save, And then rerun the same command. 3:56 You can press the Up arrow on your keyboard to bring up the last command. 4:04 Hit Enter to run the file, and we get two messages again. 4:10 But their order has switched, just like our print statements. 4:15 Python files will run from top to bottom. 4:19 So whichever print statement it encounters first will be printed out first. 4:23 Amazing job, Pythonistas, I encourage you to create some variables of your own, 4:28 and practice printing them out and running the file in the console. 4:33 When you're ready, I'll see you in the next video. 4:37
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up