Python – Getting Started

In this lesson, you will learn the basics of a Python program, the syntax, and how to create a Python project using PyCharm IDE. Please refer to the previous lesson for more information about how to install the PyCharm application.

Your First Python Program

The “Hello World” Example is a simple program that outputs “Hello world” to the console.

Hello World Example in Python

In Python, the famous Hello World program syntax is shown below:

print("Hello World!")

Program Output

Hello World!

To run this program on your local computer:

  • Open Python from the start menu (or search for it using the windows search function)

  • Type or copy/paste the code in the console

  • Hit the Enter key

Later in this lesson, we will explain how to use the PyCharm application that you installed in the previous lesson to create a Python project.

Python Indentation

Unlike most programming languages that use indentation for readability purposes, the indentation in Python is essential and can lead to syntax errors if not used properly.

 Note: Indentation refers to the spaces that you add before the line begins.  

The code below is an example of indentation in Python:

if 2 > 1: 
   print("2 is always greater than 1")

But if you write the same program without indentation:

if 2 > 1: 
print("2 is always greater than 1")

Python will throw an error

IndentationError: expected an indented block

Using the PyCharm IDE

A great way to keep your Python code clean and indented the right way, as well as creating projects, managing files, and deploying your solutions is to use an IDE (Integrated Development Environment).

Create a new Python Project in PyCharm

Follow the steps below to create a new project in PyCharm

  1. Open PyCharm from the start menu.
  2. Once PyCharm opens, click on “New Project”
  3. In the Location Field, change the Project name to “MyPythonProject” (C:\Users\xxx\PycharmProjects\MyPythonProject)
  4. Click the Create button

By default, PyCharm will create the main.py file for you. We can use it to try the “Hello World” example:

Add new files to your project

To add a new file to your project:

  1. In the right pane, right-click on the project name -> New -> Python File
  2. Name your New file “MyClass”

Things to Remember

  • Python REquired Indentation or it will throw an error
  • PyCharm is a great IDE for Python Development
Back to: Learn Python > Introduction to Python

Leave a Reply

Your email address will not be published. Required fields are marked *