Hello World
Creating a "Hello, World" Program in PyCharm
WithNow that we have Python, Mamba, and PyCharm setupset weup, can nowlet's create a basicsimple "Hello, World" program. In order to do this we can clear what's in our main.py file.
Now that there is no code in the project, cliking the Run button doesn't actually generate any output. All PyCharm tells us is that the program executed without crashing, which is what we'd expect from a file with no code.
Now let's create our Hello World code. In order toTo do this, we will writecreate a new Python file using the following steps:
- Right-click on your
first-pycharm-project
folder. - Go to "New" and select "Python File."
You'll now be prompted to choose a file name and select the "type" of Python file you want PyCharm to create. For this example, let's name the file hello.py
and choose the file type as "Python file." While this might seem redundant, you'll see that there's a reason PyCharm offers the other file types.
Press Enter, and a new Python file named hello.py
will be created. You can verify its creation by checking the files listed in the project tool window. The empty hello.py
file will also open in the editor.
ust like before, you can run the newly created Python file. However, since there's no code in it yet, you won't see any meaningful output. It will simply indicate that the program finished with exit code 0, as we'd expect no errors to occurr seeing as we haven't even writen any code yet.
To create a "Hello, World" program, we'll use a print()
statement. In Python, print()
is a command built into Python that is capable of sendingsends output to ourthe terminal.console. Inside the brackets of print()
, we provide the text we want Python to print. This text must be enclosed in quotation marks so that Python knows where it begins and ends. Here's what the code looks like:
print("Hello, World")
If you type out those code letter-by-letter, you'll notice that PyCharm's auto-complete feature can assist you. As you start typing "pri," PyCharm will suggest commands that contain that text. When "print" is selected you can then press Enter and PyCharm will automatically add the remaining characters, including the parentheses, and place your cursor between the brackets, where you can type what it is you want to print.
In this example, I waited until I had typed out "prin" before employing auto-complete's help, but I could have done it sooner. As you type out more, you narrow down PyCharm's list of potential ways for completing your code.
Additionally, PyCharm will automatically create a closing quotation marks when you type an opening one, saving you time. This is also a feature frequently found in IDEs.
With the print("Hello, World")
code in place, you can run the program again. This time, you'll see meaningful output.
Now thatyou we'vehave donesuccessfully that,created we can hitand run again.your "Hello, World" program in PyCharm. This timeis wea getsimple somethingyet moreessential step in thegetting output.started with Python programming.