Python is a high-level, interpreted programming language known for its simplicity and readability. It is widely used in web development, data science, automation, AI, and more.
Created by Guido van Rossum Released in 1991
- Created by Guido van Rossum in 1989.
- Officially released in 1991 as version 0.9.0.
- Named after the TV show “Monty Python’s Flying Circus” — not the snake! 🐍😂
- Current stable version (as of 2025): Python 3.x
Python is a powerful, high-level programming language known for its readability and versatility. It's used in a wide range of fields, including:
- Web Development – Frameworks like Django and Flask make building web apps quick and efficient.
- Data Science & Machine Learning – Libraries like Pandas, NumPy, scikit-learn, and TensorFlow power data analysis and AI models.
- Automation & Scripting – Perfect for automating tasks, scraping websites, or managing systems.
- Software Development – Build full-scale applications or use Python as a supporting language for backend systems.
- Cybersecurity – Frequently used for writing tools, scanning vulnerabilities, and building automation for security tasks.
- Game Development – Libraries like Pygame allow developers to prototype and build simple games.
- Internet of Things (IoT) – Works with Raspberry Pi and microcontrollers to create hardware-based projects.
- Download Python from the official Python website.
- Run the installer and check "Add Python to PATH".
- Click Install and wait for completion.
- Open Command Prompt and type:
python --version
brew install python
python3 --version
sudo apt update && sudo apt install python3
python3 --version
- Install from https://code.visualstudio.com
- Install the Python extension (Microsoft) Create .py file and run it using terminal or “Run” button
- Great for data science and experimentation
- Install via pip:
pip install notebook
jupyter notebook
- Install from https://www.jetbrains.com/pycharm/
- Professional (paid) vs Community (free)
- Feature-rich with code completion and debugger
Let’s write your very first Python program:
print("Hello, World!")
python hello.py
Hello, World!
You’ve just written your first Python program! 🎉
Used to explain code and make it more readable. Ignored during execution.
Single-line comment:
# This is a single-line comment
print("Hello")
Multi-line comment (not official, but using multiple # lines or strings):
# This is a
# multi-line
# comment
Used to describe modules, functions, classes, or methods.
def greet():
"""This function prints a greeting message."""
print("Hello!")
You can access the docstring like this:
print(greet.__doc__)
name = "Alice" # string
age = 25 # integer
height = 5.7 # float
is_student = True # boolean
Type | Example |
---|---|
int | 10 , -3 |
float | 3.14 , -0.5 |
str | "hello" |
bool | True , False |
list | [1, 2, 3] |
tuple | (1, 2, 3) |
dict | {"a": 1, "b": 2} |
- Python is dynamically typed, so you don’t need to declare the type explicitly.
Convert values between data types:
x = "10"
y = int(x) # str to int
z = float(x) # str to float
s = str(25) # int to str
print(type(y)) # <class 'int'>
- Common casting functions:
int()
,float()
,str()
,bool()
print("Hello", "World", sep=", ", end="!\n") # Hello, World!
name = input("Enter your name: ")
print("Hello, " + name)
input()
always returns a string. Cast it if needed:
age = int(input("Enter your age: "))
Operator | Description | Example (a = 10 , b = 3 ) |
Result |
---|---|---|---|
+ |
Addition | a + b |
13 |
- |
Subtraction | a - b |
7 |
* |
Multiplication | a * b |
30 |
/ |
Division | a / b |
3.33 |
// |
Floor Division | a // b |
3 |
% |
Modulus | a % b |
1 |
** |
Exponentiation | a ** b |
1000 |