Pi
Pi
This file includes all the essential topics you need to learn in Python. Once you master these, you
will be ready to use any specialized libraries based on your field (ethical hacking, web development,
1. Variables
name = "Ali"
age = 25
2. Data Types
- String: "hello"
- Integer: 5 U
- Float: 3.14
- List: [1, 2, 3]
- Tuple: (1, 2, 3)
- Set: {1, 2, 3}
3. Operators
+ - * / // % **
4. If Statements
if age >= 18:
print("Adult")
else:
print("Minor")
5. Loops
for i in range(5):
print(i)
while condition:
# do something
6. Functions
def greet(name):
print("Hello", name)
7. File Handling
data = f.read()
8. Data Structures
9. Exception Handling
try:
x=1/0
except ZeroDivisionError:
print("Cannot divide by zero")
10. Libraries
import math
print(math.sqrt(16))
import datetime
now = datetime.datetime.now()
print(now)
import requests
res = requests.get("http://example.com")
print(res.text)
class Hacker:
self.name = name
h = Hacker("Ali")
print(h.name)
14. OS Interaction
import os
os.system("ls")
15. Networking
import socket
ip = socket.gethostbyname("example.com")
print(ip)