Hello World
Creating a "Hello, World" Program in PyCharm
Now that we have Python, Mamba, and PyCharm set up, let's create a simple "Hello, World" program. To do this, we will create 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 that sends output to the 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 you have successfully created and run your "Hello, World" program in PyCharm. This is a simple yet essential step in getting started with Python programming.