0% found this document useful (0 votes)
6 views1 page

Python Bible: Coding Best Practices

The document outlines essential Python programming rules, do's and don'ts, and examples across three chapters: Basics & Syntax, Data Types, and Strings. Key points include mandatory indentation, case sensitivity, and the use of specific naming conventions. It emphasizes the importance of avoiding common pitfalls such as mixing tabs and spaces, overwriting built-in names, and improper float comparisons.

Uploaded by

Ramano Aj
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Python Bible: Coding Best Practices

The document outlines essential Python programming rules, do's and don'ts, and examples across three chapters: Basics & Syntax, Data Types, and Strings. Key points include mandatory indentation, case sensitivity, and the use of specific naming conventions. It emphasizes the importance of avoiding common pitfalls such as mixing tabs and spaces, overwriting built-in names, and improper float comparisons.

Uploaded by

Ramano Aj
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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
...

You might also like