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?
| Area | Example |
|---|---|
| Web development | Backend of a website with Django or Flask |
| Data analysis | Studying the monthly sales of a shop |
| Artificial intelligence | Chatbots, image recognition, predictions |
| Automation | Renaming 500 files or sending reports by email |
| Scripting | Small tools that save you time every day |
Install Python
- Go to the official website python.org and open the Downloads page.
- Download the latest Python 3 version for your system.
- On Windows, tick the box "Add python.exe to PATH" before you click Install.
- Finish the installer.
To check that it worked, open the Command Prompt (Windows) or Terminal (macOS/Linux) and type:
Example
python --versionPython 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
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
python hello.pyHello, 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
>>> 5 + 7
12
>>> print("Salam")
SalamThe 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?
