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
Python Tutorial | Learn Python Programming Language
Python Tutorial â Python is one of the most popular programming languages. Itâs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly.Python is:A high-level language, used in web development, data science, automatio
10 min read
Python Interview Questions and Answers
Python is the most used language in top companies such as Intel, IBM, NASA, Pixar, Netflix, Facebook, JP Morgan Chase, Spotify and many more because of its simplicity and powerful libraries. To crack their Online Assessment and Interview Rounds as a Python developer, we need to master important Pyth
15+ min read
Python OOPs Concepts
Object Oriented Programming is a fundamental concept in Python, empowering developers to build modular, maintainable, and scalable applications. By understanding the core OOP principles (classes, objects, inheritance, encapsulation, polymorphism, and abstraction), programmers can leverage the full p
11 min read
Python Projects - Beginner to Advanced
Python is one of the most popular programming languages due to its simplicity, versatility, and supportive community. Whether youâre a beginner eager to learn the basics or an experienced programmer looking to challenge your skills, there are countless Python projects to help you grow.Hereâs a list
10 min read
Python Exercise with Practice Questions and Solutions
Python Exercise for Beginner: Practice makes perfect in everything, and this is especially true when learning Python. If you're a beginner, regularly practicing Python exercises will build your confidence and sharpen your skills. To help you improve, try these Python exercises with solutions to test
9 min read
Python Programs
Practice with Python program examples is always a good choice to scale up your logical understanding and programming skills and this article will provide you with the best sets of Python code examples.The below Python section contains a wide collection of Python programming examples. These Python co
11 min read
Enumerate() in Python
enumerate() function adds a counter to each item in a list or other iterable. It turns the iterable into something we can loop through, where each item comes with its number (starting from 0 by default). We can also turn it into a list of (number, item) pairs using list().Let's look at a simple exam
3 min read
Python Data Types
Python Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, Python data types are classes and variables are instances (objects) of thes
9 min read
Python Introduction
Python was created by Guido van Rossum in 1991 and further developed by the Python Software Foundation. It was designed with focus on code readability and its syntax allows us to express concepts in fewer lines of code.Key Features of PythonPythonâs simple and readable syntax makes it beginner-frien
3 min read
Input and Output in Python
Understanding input and output operations is fundamental to Python programming. With the print() function, we can display output in various formats, while the input() function enables interaction with users by gathering input during program execution. Taking input in PythonPython input() function is
8 min read