Creating Your First Application in Python
Last Updated :
27 May, 2025
Python is one of the simplest and most beginner-friendly programming languages available today. It was designed with the goal of making programming easy and accessible, especially for newcomers. In this article, we will guide you through creating your very first Python application from a simple print statement to interacting with a database. Before we start coding, it’s helpful to be familiar with these foundational Python concepts:
If you understand these basics, you will find the rest of this article much easier to follow.
Step 1: Your First Python Program
Let’s start with a simple application that prints a welcome message by following the steps below:
1. Open any text editor you like (Notepad, VSCode, PyCharm, etc.) and write the following Python code:
print("Welcome to GeeksForGeeks!")
2. Save the file as gfg.py (the .py extension tells the system it’s a Python file).
3. Open your terminal or command prompt and navigate to the folder where gfg.py is saved and run the program by typing:
python gfg.py
4. This will result in Python executing the code in the gfg.py file as shown below:

Congratulations! You have just created and run your first Python program.
Step 2: Making the Application Interactive (Odd or Even Number Checker)
Now, let’s make your program interactive. This time, it will determine whether a given number is odd or even by following the steps below:
1. First, we need to get a number from the user. In Python, use the input() function, and convert the input string to an integer using int():
num = int(input("Enter a number: "))
2. Next, use a conditional statement to check if the number is divisible by 2:
if num % 2 == 0:
print("It's an Even number!")
else:
print("It's an Odd number!")
3. Combine these into one script and save it as gfg.py:
Python
num = int(input("Enter a number: "))
if num % 2 == 0:
print("It's an Even number!")
else:
print("It's an Odd number!")
4. Run it again via the command line:
python gfg.py
5. Enter any integer when prompted. The program will tell you if it’s odd or even.

Here we are now, with a successfully built interactive python application.
Step 3: Connecting Your Python Application to a PostgreSQL Database
Most real-world applications need to store and retrieve data. Let’s see how to connect your Python program to a PostgreSQL database and insert data by following the steps below. But first, you’ll need the following:
- PostgreSQL installed on your machine
- psycopg2 Python library (used to interact with PostgreSQL)
Let's undestand step by step approch:
Step 3.1: Install psycopg2
Open your terminal or command prompt and run the following command to install the psycopg2 library:
pip install psycopg2
Step 3.2: Set Up the PostgreSQL Database
1. Open the PostgreSQL shell (psql) and connect using your user credentials and create a new database:
CREATE DATABASE test_db;
2. Connect to the newly created database:
\c test_db
3. Create a table to store data (for example, names):
CREATE TABLE test_names (
name VARCHAR(50)
);
Step 3.3: Write Python Code to Insert Data
1. Open a text editor (like Notepad, VSCode, or PyCharm) and write the following Python code:
Python
#!/usr/bin/python
import psycopg2
try:
# Connect to the database
conn = psycopg2.connect(
host="localhost",
dbname="test_db",
user="postgres",
password="your_password"
)
cur = conn.cursor()
# Insert data
cur.execute("INSERT INTO test_names (name) VALUES (%s)", ("Ramadhir",))
conn.commit()
print("Data inserted successfully!")
except Exception as e:
print(f"Error: {e}")
finally:
# Close resources
if cur:
cur.close()
if conn:
conn.close()
Note: Replace "your_password" with your actual PostgreSQL password. Using parameterized queries (%s) helps prevent SQL injection.
2. Save this file as gfg.py.
Step 3.4: Run the Script
1. Open your terminal, navigate to the folder where gfg.py is saved, and run the script:
python gfg.py
2. You should see the message:
Data inserted successfully!
Step 3.5: Verify the Data Insertion
1. Go back to the PostgreSQL shell and run the following SQL query:
SELECT * FROM test_names;
2. You should see the inserted name displayed:

Congratulations! You’ve successfully connected your Python application to a PostgreSQL database and inserted your first data entry.
Related articles
Similar Reads
Create First GUI Application using Python-Tkinter We are now stepping into making applications with graphical elements, we will learn how to make cool apps and focus more on its GUI(Graphical User Interface) using Tkinter.What is Tkinter?Tkinter is a Python Package for creating GUI applications. Python has a lot of GUI frameworks, but Tkinter is th
12 min read
Flask - (Creating first simple application) Building a webpage using python.There are many modules or frameworks which allow building your webpage using python like a bottle, Django, Flask, etc. But the real popular ones are Flask and Django. Django is easy to use as compared to Flask but Flask provides you with the versatility to program wit
6 min read
PyQt in Python : Designing GUI applications Building GUI applications using the PYQT designer tool is comparatively less time-consuming than coding the widgets. It is one of the fastest and easiest ways to create GUIs. The normal approach is to write the code even for the widgets and for the functionalities as well. But using Qt-designer, one
5 min read
Creating Your Own Python IDE in Python In this article, we are able to embark on an adventure to create your personal Python Integrated Development Environment (IDE) the usage of Python itself, with the assistance of the PyQt library. What is Python IDE?Python IDEs provide a characteristic-rich environment for coding, debugging, and goin
3 min read
What is Python? Its Uses and Applications Python is a programming language that is interpreted, object-oriented, and considered to be high-level. What is Python? Python is one of the easiest yet most useful programming languages and is widely used in the software industry. People use Python for Competitive Programming, Web Development, and
8 min read
Python Pyramid - Creating A Project This project is a dynamic web application built on the powerful Python Pyramid framework. In this, we'll go through the comprehensive overview of the prerequisites you should have before diving into Pyramid, as well as the essential steps to get started with this powerful web framework. Pyramid enab
4 min read
How to Create GUI Applications Under Linux Desktop Using PyGObject The creation of applications in Linux can be done through various methods. But, the most efficient way of creating a GUI application in Linux can be done through PyGObject in  Python. PyGObject is the next generation from the PyGTK library in Python, we can say that PyGObject = Python + GTK3. So, in
6 min read
Packaging and Publishing Python code If you have been coding in python, even for a while, you must be familiar with the concept of 'pip' by now. It is a package management system used to install and manage software packages/libraries written in Python. Then one may ask that where are all these packages/libraries stored? It is obvious t
7 min read
Joke Application Project Using Django Framework We will create a simple Joke application using Django. By using the pyjokes package, weâll build a web app that generates and displays random jokes. Weâll go step-by-step to set up the project, configure the views, and render jokes dynamically on the homepage.Install Required PackagesFirst, install
2 min read
Introduction to Python for Absolute Beginners Are you a beginner planning to start your career in the competitive world of Programming? Looking resources for Python as an Absolute Beginner? You are at the perfect place. This Python for Beginners page revolves around Step by Step tutorial for learning Python Programming language from very basics
6 min read