Python Tutorial menu

Python Introduction

Python is a programming language that is simple to learn and powerful enough for real work.

What is Python?

  • Python is a general-purpose programming language. You can use it for almost any kind of program.
  • It was created by Guido van Rossum and first released in 1991.
  • It is interpreted: you do not need to compile your code first. Python reads and runs it line by line.
  • It is free and open source.

What Can You Do With Python?

AreaExample
Web developmentBackend of a website with Django or Flask
Data analysisStudying the monthly sales of a shop
Artificial intelligenceChatbots, image recognition, predictions
AutomationRenaming 500 files or sending reports by email
ScriptingSmall tools that save you time every day

Install Python

  1. Go to the official website python.org and open the Downloads page.
  2. Download the latest Python 3 version for your system.
  3. On Windows, tick the box "Add python.exe to PATH" before you click Install.
  4. Finish the installer.

To check that it worked, open the Command Prompt (Windows) or Terminal (macOS/Linux) and type:

Example

bash
python --version
Output
Python 3.13.0

Your number may be different. Anything that starts with 3 is fine.

On macOS and Linux the command is often python3 instead of python. If one does not work, try the other.

Your First Program

Open any text editor (Notepad, or better, VS Code) and type this line:

Example

python
print("Hello, Karachi!")

Save the file as hello.py. The .py ending tells the computer that it is a Python file. Now run it from the terminal, in the folder where you saved it:

Example

bash
python hello.py
Output
Hello, Karachi!

Congratulations, you have written and run a Python program.

The Python Shell

You can also type Python code directly, one line at a time. Type python in the terminal and press Enter. You will see >>>, which means Python is waiting for you:

Example

python
>>> 5 + 7
12
>>> print("Salam")
Salam

The shell is great for quick tests. Type exit() to leave it. For longer programs, save your code in a .py file.

Python 2 or Python 3?

Python 2 is old and no longer supported. Always use Python 3. Everything in this tutorial uses Python 3.

Exercise

Exercise

Which file ending is used for Python files?

Learn Python with a teacher

Join the Python Programming course at Workownix, online or in Orangi Town, Karachi, and get a certificate.

See the course Ask on WhatsApp