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
Python - Quiz Application Project
Python provides us with many libraries to create GUI(Graphical User Interface), and Tkinter is one of them. Creating GUI with Tkinter is very easy and it is the most commonly used library for GUI development. In this article, we will create a Quiz application using Tkinter. A Quiz application has a
4 min read
Love Calculator GUI Application in Python
In this article, we are going to know how to make a GUI love calculator application using python. Prerequisite: Tkinter application, Python Random function. There are multiple ways in python to build a GUI(Graphical User Interface). Â Among all of those, the most commonly used one is Tkinter. It's th
5 min read
Creating Multipage Applications Using Streamlit
In this article, we will see how to make a Multipage WebApp using Python and Streamlit. What is Streamlit? Streamlit is an Open Source framework especially used for tasks related to Machine Learning and Data Science. It can create web apps with a very less amount of code. It is widely used because
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
Top 10 Python Applications in Real World
We are living in a digital world that is completely driven by chunks of code. Every industry depends on software for its proper functioning be it healthcare, military, banking, research, and the list goes on. We have a huge list of programming languages that facilitate the software development proce
6 min read
Create a directory in Python
In Python, you can create directories to store and manage your data efficiently. This capability is particularly useful when building applications that require dynamic file handling, such as web scrapers, data processing scripts, or any application that generates output files.Let's discuss different
3 min read