Python Bible – Rules, Do’s & Don’ts, Examples
Chapter 1 – Basics & Syntax
Rules
- Indentation is mandatory (default = 4 spaces).
- Python is case-sensitive.
- Code blocks end with indentation, not {}.
Do’s
- Use snake_case for variables, PascalCase for classes.
- Keep line length under 79 characters (PEP 8).
Don’ts
- Don’t mix tabs and spaces.
- Don’t overwrite built-in names (list, dict, etc.).
Example:
user_name = "Ajay" # Good
List = [1, 2, 3] # Bad, overwrites built-in list
-----------------------------------------------------
Chapter 2 – Data Types
Rules
- Python is dynamically typed.
- Use type() to check data type.
Do’s
- Use [Link] or [Link] for precision.
Don’ts
- Don’t compare floats directly.
Example:
0.1 + 0.2 == 0.3 # False
import math
[Link](0.1 + 0.2, 0.3) # True
-----------------------------------------------------
Chapter 3 – Strings
Rules
- Strings are immutable.
- Use single ' or double " consistently.
Do’s
- Use f-strings (f"Hello {name}").
Don’ts
- Don’t use + in loops for concatenation → use join().
Example:
name = "Ajay"
print(f"Hello {name}") # Good
s = ""
for word in ["I", "love", "Python"]:
s += word # Bad
...