Creating Your First Application in Python
Last Updated :
19 Oct, 2021
Python is one of the simplest programming language out there. In fact, it was developed for the sole purpose of simplifying the process of learning a programming language and exposed beginners to the concepts of Programming. In this article, we will be building a Python Application. Not to worry it won't be anything fancy or complex. But before we start make yourself familiar with these Python Concepts:
Once you get familiar with the above concepts the content of the rest of this article will be easy to grasp. Now, let's move on to building the application. For the sole reason of simplicity, we will be building an application that greets the user with a "Welcome to GeeksForGeeks!" message when executed.
To do so follow the below steps:
- Step 1: Open an editor of your choice to write the Python code. Here we will simply use Notepad but it is completely up to you what you prefer.
- Step 2: Now write the below code in the editor:
Python3
# code
print("Welcome to GeeksForGeeks!")
- Step 3: Now that we have completed the code save it as gfg.py ('gfg' is just a name that we gave to the python file)
- Step 4: Now it's time to run the python code so open up the terminal that your OS provides and move to the directory (it's on Desktop in this case) where the file has been saved. Here we will be using Command Prompt.

- Step 5: Now make a call to the python interpreter from the cmd to run the gfg application as below:
python gfg.py
This will result in Python executing the code in the gfg.py file as shown below:
Congratulations!! You have successfully built your first Python Application that greets the user with the "Welcome to GeeksForGeeks!" message when executed.
Now let's step it up a bit. What if you desire to make your Python application a bit more interactive. Suppose you want the Python application to find out whether a given number is odd or even? Let's just do that by following the below steps:
- Step 1: We will be needing a variable to store the number that we are going to give it to test. So let's declare a variable(say, num) as below:
num = int(input())
Here we have a variable  named num that is equal to the number received by the input() function and is an integer data type.Â
- Step 2: As the num variable receives the number, we will use a conditional statement to check if the number in the num variable is divisible by 2 or not. To do so use the below code snippet:
if num%2 == 0:
print("It's an Even number!")
else:
print("It's an Odd number!")
In the above code, we Divided the value in the num variable with 2 using the Modulus (%) operator, and depending upon what the operator returns will decide if the given number is odd or even. If it returns a quotient of 0 that it's an even number else it is odd.
- Step 3: Now aggregate the above code snippets and save it into the gfg.py file as below:
Python3
num = int(input())
if num%2 == 0:
print("It's an Even number!")
else:
print("It's an Odd number!")
Â
Â
- Step 4: Now run the file similar to the way we run it in the cmd and the behavior is as expected:
Here we are now, with a successfully built interactive python application.
Now let's move a bit further. As every application more or less needs a stable database for it's functioning, let's explore the process of connecting your application with a database. For the purpose of demonstration, we will build an application that store some sort of information provided by the user in a PostgreSQL database. To install PostgreSQL in your Windows, Mac, or Linux visit the respective links.
Let's build an application that takes information from the user (say, names) and stores in the database. To do so follow the below steps:Â
- Step 1: As the psycopg2 module provides an API for Python to interact with the database install the same using the below command:
pip install psycopg2
- Step 2: Now open the psql shell fill in your credentials and create a database(say, test_db) using the below statement:
CREATE DATABASE test_db;
- Step 3: To establish a connection with the database use the below code:
db_conn = psycopg2.connect("dbname=test_db user=postgres password=postgres")
- Step 4: All that is set but we will also be needing a table (say, test_name) using the below statement:
CREATE TABLE department_employee(
test_names CHAR(50)
);
- Step 5: Now we have set up the database and the table, let's complete the gfg.py script to connect with the database and execute the INSERT statement to insert the data to the table:
Python3
#!/usr/bin/python
import psycopg2
# Establish the connection to PostgreSQL
db_conn = psycopg2.connect("host=localhost dbname=test_db user=postgres password=5555")
#create a cursor object from connection module
cursor_object = db_conn.cursor()
# Add data into the test_names table of test_db
cursor_object.execute("INSERT INTO test_names (name) VALUES ('Ramadhir')")
# Save the changes to database
db_conn.commit()
- Step 6: Now execute the above gfg.py to make the changes to the database as follow:
python gfg.py
- Step 7: Now verify the changes using the below command in psql shell:
SELECT * FROM test_names;
This will lead to the following output:
Walla!!! We have successfully added data to a PostgreSQL database at this point.
Conclusion:
At this point, we have managed to create applications that make the use of variables, loops, functions, conditional statements, user input, and a database. You can explore plenty of Python modules that age available on GeeksforGeeks to expand your application and design it according to your requirements.
To explore Python concepts visit Python Tutorial section of GeeksForGeeks.
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