From the course: Python Essential Training

Writing a program - Python Tutorial

From the course: Python Essential Training

Writing a program

- [Instructor] Okay, let's get warmed up. We're going to be writing our first Python program. For this you can use any text editor you'd like. I recommend Visual Studio Code, which I'm using, or you can use something like Sublime or PyCharm. If you're using Windows, you can also use Notepad++ which I've used in the past. If you don't have a text editor, pause now and go get one. We'll be using them for the challenges in this course and a text editor is an essential tool for programming in any language. So create a file called hello.py; hello.py. And open it in your text editor of choice. PY is the file extension for all Python files. And we're just going to type a single line of Python code that will print the text Hello, World! to the screen. So this is the print function. It takes whatever text is passed into these parentheses and just prints it out to the terminal. And notice that I've surrounded the text with these single quotes. So this isn't actually part of the text, but it tells Python, okay, I'm about to start writing some text. So these quotes are important. We can also write a comment. So let's give us a couple lines of space. Comments start with a hash, and this is just human readable text that's completely ignored by the computer when it's running the program. So comments are handy to make notes to other programmers or remind yourself what a line is doing. And I'm just going to write the comment, print hello, world! to the terminal. Great. Now save this file. Then go to the terminal or command prompt. Navigate to where your file is stored. Use the cd command, which stands for change directory. And I'm going to type cd Documents GitHub python-essential-training. Now I'm not actually typing that fast. So if you don't know, you can use the tab key to auto complete directory names. So just type cd doc tab gi tab py tab. And I can do ex tab to get to the exercise files and then enter. So now that I'm here, I can run our hello.py file with the Python command python hello.py, or I can just type h and then tab and then that auto completes. Now previously we've just typed Python to get to the Python command prompt, and here we're typing python and then the name of a file. So this tells Python to run the file as a Python program, and we can see that our file is run and it prints out Hello, World! So congratulations, you are now a Python programmer. Go take a break, add Python to your LinkedIn skills section, and join me back here as we put this into practice.

Contents