10 Coding Principles I Wish I Knew When I Started Python
If I could go back in time, these 10 coding principles would’ve saved me from messy code, wasted hours, and painful rewrites. Learn them…

I wrote a lot of Python before I wrote good Python — and the difference came down to principles, not features.
10 Coding Principles I Wish I Knew When I Started Python
If I could go back in time, these 10 coding principles would’ve saved me from messy code, wasted hours, and painful rewrites. Learn them now — thank yourself later.
When I first began my Python journey, I thought I was doing great.
I could write functions. I could loop through lists. I could even build a simple app or two.
But looking back, I realize I wasn’t writing Pythonic code.
I was writing JavaScript or C-style logic in Python syntax.
I was missing out on the elegance, simplicity, and power the language offers.
Here are the principles I wish someone had drilled into me from day one.
If you’re just starting out — or even if you’ve been coding in Python for a while — these insights might just change how you write code forever.
1. Readability Is Not Optional — It’s Everything
“Code is read much more often than it is written.” — Guido van Rossum
Python wasn’t designed to be clever. It was designed to be clear.
I used to write long, nested if-else
chains, complex one-liners, or overcomplicated loops. Eventually, I realized that if my future self or a teammate couldn’t understand my code instantly, it wasn’t good code.
Better approach:
# Bad
if status == 'active':
if user_role == 'admin':
do_something()
# Good
if status == 'active' and user_role == 'admin':
do_something()
Follow PEP8. Use meaningful variable names. Add comments where needed — but aim to write code that doesn’t need explaining.
2. There’s a Pythonic Way to Do It
Python has idioms — ways of doing things that are unique to the language. When you start thinking in Python, your code becomes shorter, cleaner, and more elegant.
Examples that changed the way I write:
- Use list comprehensions instead of
for
loops - Use unpacking to swap variables or access elements
- Use
any()
orall()
instead of long logical conditions
# Instead of this
result = []
for x in items:
if x > 10:
result.append(x)
# Do this
result = [x for x in items if x > 10]
Get familiar with the Zen of Python (import this
). It’s not just poetic—it’s a mindset.
3. Stop Reinventing the Wheel — Use the Standard Library
I used to write my own JSON parser (yes, seriously), my own timer functions, and even my own argument parsers.
Python’s standard library is a goldmine.
It has modules for everything from web servers to date parsing to working with files, strings, math, and more.
import json
data = '{"name": "Aashish", "age": 25}'
parsed = json.loads(data)
The saying is true: “Batteries included.” Learn what’s already available before building it from scratch.
4. Write Fewer Lines, Not Smarter Lines
Early on, I thought writing code in one line made me look like a 10x developer.
All I was really doing was writing unreadable spaghetti.
This line I once wrote still haunts me:
result = [x for x in items if x % 2 == 0 and x > 10 and some_func(x) not in cache or backup.get(x)]
Just… don’t.
Break things down.
Use functions.
Be kind to the person who will read this next — probably you.
5. Master the Power of Functions (and Write Them Like You Mean It)
Functions aren’t just reusable chunks — they’re the building blocks of good design.
When I started, my functions were long, vague, and did way too many things.
What I learned:
- A function should do one thing and do it well.
- The name should describe what it does, not how it does it.
- Keep it small — ideally less than 10 lines.
# Bad
def process(data):
# does validation, filtering, formatting, and writing
...
# Good
def validate(data): ...
def filter_valid_entries(data): ...
def format_entries(data): ...
def write_to_file(data): ...
6. Exceptions Are Not Evil — They’re Expected
I used to write 10 if-else
checks just to make sure I wasn’t dividing by zero or accessing a non-existent key.
Then I learned Python’s EAFP principle: Easier to ask for forgiveness than permission.
Use try/except
. Let it fail gracefully. That’s the Python way.
# Instead of
if 'name' in data:
print(data['name'])
# Do this
try:
print(data['name'])
except KeyError:
print("Name not found")
It’s cleaner and handles the unexpected with elegance.
7. Testing Isn’t Optional — Even for Small Scripts
If your code isn’t tested, it’s broken. You just don’t know it yet.
I used to “eyeball” my output and feel confident.
But as my scripts grew, bugs slipped in.
Learning how to write unit tests — even for basic functions — gave me confidence.
It also made refactoring easier and helped me spot edge cases I hadn’t considered.
Start simple:
def add(a, b):
return a + b
def test_add():
assert add(2, 3) == 5
You don’t need a full testing framework right away. But get into the habit early.
8. Embrace the REPL and Jupyter for Rapid Experimentation
One of Python’s greatest strengths is how easy it is to test ideas interactively.
Don’t write a full file just to check if a list comprehension works.
Open the Python shell. Use ipython
. Fire up Jupyter. Play.
Exploration helps learning stick.
9. Use Virtual Environments From Day One
Nothing ruins a project faster than a broken dependency mess.
Use venv
or virtualenv
to isolate your project dependencies. It's a simple practice that saves hours of debugging.
python -m venv env
source env/bin/activate
pip install flask
Trust me — future you will thank you.
10. Keep Learning, Always
Python is deep.
There’s always more to explore: decorators, generators, context managers, async programming, type hinting.
Don’t try to learn it all at once.
But never stop learning.
I still go back to beginner tutorials to re-learn concepts I now understand better through experience.
Final Thoughts
If you’re just starting your Python journey, remember this:
Write code that’s clean, simple, and expressive. Lean into Python’s strengths. Learn the idioms. Use the tools. And always, always write for humans first — computers second.
The code you write today is a letter to the coder you’ll be tomorrow.
Make it a good one.
If you found this useful, consider following me for more Python lessons, dev insights, and real-world coding strategies.
