TURN ON POST 2025
NOTIFICATIONS PYCODE.HUBB
PYTHON
PYTHON
CHEATSHEET
CHEATSHEET
AKASH • PY THON & TECH ENTHUSIAST
@PYCODE.HUBB
TURN ON POST 2025
NOTIFICATIONS PYCODE.HUBB
BASIC PY THON SYNTAX
1. Print to Console: print("Hello, World!")
2. Variable Assignment: a = 'pycode.hubb'
3. Commenting: # This is single line comment!
4. Multi-line Comment: """This is a multi-line comment!"""
5. Input from User: name = input("Enter your name: ")
6. Check Data Type: type(x)
7. Type Casting: int("10"), float("10.5"), str(100)
DATA STRUCTURES
1. List (Array): my_list = [1, 2, 3, 4, 5]
2. Access List Item: my_list[0]
3. List Slicing: my_list[1:4]
4. Add Item to List: my_list.append(6)
5. Remove Item from List: my_list.remove(3)
6. Tuple: my_tuple = (1, 2, 3, 4)
7. Set: my_set = {1, 2, 3, 4}
8. Dictionary: dict = {"key1": "val1", "key2": "val2"}
9. Access Dictionary Value: my_dict["key1"]
10. Add Key-Value Pair: my_dict["key3"] = "value3"
AKASH • PY THON & TECH ENTHUSIAST
@PYCODE.HUBB
TURN ON POST 2025
NOTIFICATIONS PYCODE.HUBB
CONTROL FLOW
1. If Statement: if x > 10: print("x is greater than 10")
2. If-Else Statement: if x > 5: print("x is high") else: print("x is low")
3. Elif Statement: if x > 10: print("x is high") elif x > 5: print("x is avg") else: print("x is low")
4. For Loop: for i in range(5): print(i )
5. While Loop: x = 0 while x < 10: x += 1
6. Break: for i in range(5): if i == 3: break
7. Continue: for i in range(5): if i == 3: continue
FUNCTIONS
1. Define Function: def my_function(): print("Hello from function!")
2. Function with Parameters: def greet(name): print(f"Hello, {name}!")
3. Return Value from Function: def add(a, b): return a + b
4. Lambda Function: add = lambda a, b: a + b
STRING MANIPULATION
1. Concatenate Strings: full _ name = "Pycode" + "Hubb"
2. String Length: len("Hello")
3. Convert to Upper Case: "hello".upper()
4. Convert to Lower Case: "HELLO".lower()
5. Substring: "Hello, World!"[7:12]
AKASH • PY THON & TECH ENTHUSIAST
@PYCODE.HUBB
TURN ON POST 2025
NOTIFICATIONS PYCODE.HUBB
STRING MANIPULATION
6. Find Substring: "Hello, World!".find("World")
7. Replace Substring: "Hello, World!".replace("World", "Python")
8. Split String: "Hello, World!".split(",")
FILE HANDLING
1. Open a File: file = open("example.txt", "r")
2. Read File: content = file.read()
3. Read Line by Line: lines = file.readlines()
4. Write to a File: file = open("example.txt", "w") file.write("Hello, World!")
5. Close a File: file.close()
LIST COMPREHENSION
1. Basic List Comprehension: file = open("example.txt", "r")
2. List Comprehension with Condition: [x for x in range(10) if x % 2 == 0]
ERROR HANDLING
1. Try-Except Block: file = open("example.txt", "r")
2. Finally Block: try: x = 10 / 0 except ZeroDivisionError: print("Error!") finally: print("This runs always")
AKASH • PY THON & TECH ENTHUSIAST
@PYCODE.HUBB
TURN ON POST 2025
NOTIFICATIONS PYCODE.HUBB
WORKING WITH LIBRARIES
1. Importing a Library: import math
2. Using a Library Function: math.sqrt(16)
3. Install a Library: pip install pandas
4. Import Specific Function: from math import sqrt
NUMPY FOR NUMERICAL OPERATIONS
1. Import NumPy: import numpy as np
2. Create NumPy Array: arr = np.array([1, 2, 3, 4, 5])
3. Array Reshaping: arr = arr.reshape(5, 1)
4. Array Operations: arr + 10 arr2 = np.array([10, 20, 30, 40, 50]) arr + arr2
5. Array Slicing: arr[1:4]
6. Array Statistics: np.mean(arr) np.median(arr) np.std(arr)
PANDAS FOR DATA HANDLING
1. Import Pandas: import pandas as pd
2. Create DataFrame: df = pd.DataFrame({"Name": ["Alice"], "Age": [25]})
3. Read CSV File: df = pd.read _csv("data.csv")
4. View Data: df.head()
5. Basic Statistics: df.describe()
6. Filter Data: df[df["Age"] > 25]
AKASH • PY THON & TECH ENTHUSIAST
@PYCODE.HUBB
TURN ON POST 2025
NOTIFICATIONS PYCODE.HUBB
MATPLOTLIB FOR PLOTTING
1. Import Matplotlib: import matplotlib.pyplot as plt
2. Simple Plot: plt.plot([1, 2, 3], [4, 5, 6]) plt.show()
3. Bar Plot: plt.bar([1, 2, 3], [4, 5, 6]) plt.show()
4. Histogram: plt.hist([1, 2, 2, 3, 4, 5]) plt.show()
5. Scatter Plot: plt.scatter([1, 2, 3], [4, 5, 6]) plt.show()
AKASH • PY THON & TECH ENTHUSIAST
@PYCODE.HUBB
TURN ON POST 2025
NOTIFICATIONS PYCODE.HUBB
GRAB OUR ULTIMATE PYTHON BUNDLE!
Master Python from basic to advanced with
detailed explanations and practical experience.
🔗 Link in the Bio 🔗
AKASH • PY THON & TECH ENTHUSIAST
@PYCODE.HUBB