Python Basics Cheat Sheet
Python Basics Cheat Sheet
@Tajamulkhann
Python: A high-level, general-purpose
language.
Language Type: Interpreted and
dynamically typed.
Founder: Created by Guido van
Rossum, 1991.
Interpreter: Executes code line by line.
Uses: Used in Data Science, Web
Development, AI, etc.
Syntax: Simple and beginner-friendly.
Cross-Platform: Works on Windows,
macOS, Linux.
Open-Source: Free to use, modify, and
redistribute.
Extensive Libraries: Includes tools for
scientific computing, Web
development, Machine Learning,
Generative AI etc.
@Tajamulkhann
List: An ordered, mutable collection of
elements.
lst = [1, 2, 3, 4]
@Tajamulkhann
Variables: store data values.
x = 10
@Tajamulkhann
Numeric: Represent numbers
(integer, float, complex).
a = 10 # int
b = 3.14 # float
c = 2 + 3j # complex
@Tajamulkhann
If-Else Statements: Conditional
statements to execute specific code
blocks.
if x > 0:
print("Positive")
else:
print("Negative")
@Tajamulkhann
Self-defined Functions: Functions that
are defined by the user to perform
specific tasks.
def function_name(parameters):
return value
@Tajamulkhann
Reading Files: Open and read contents
from a file.
with open("file.txt", "r") as f:
content = f.read()
print(content)
@Tajamulkhann
Try-Except: Handle errors gracefully.
try:
x=1/0
except ZeroDivisionError:
print("Cannot divide by zero!")
@Tajamulkhann
Numpy: for numeric computations.
import numpy as np
arr = np.array([1, 2, 3])
@Tajamulkhann
Follow for more!