Readable internship code comes from a short, repeatable pre-commit routine: format with a tool, follow PEP 8 naming, write docstrings for anything public, add type hints to function signatures, and run a linter before every commit. This article gives you that routine as a checklist and a scoring table, then shows it applied to a small backend module, with a 14-day plan sized for Central University of Haryana students.
Why style matters more in a 14-day internship than in a semester project
In a classroom assignment, only you and an evaluator read your code. In an internship, a mentor or reviewer reads it quickly, often on a small screen, and decides within minutes whether your work is careful. A two-week window leaves no time to fix a messy habit late. Style is the cheapest quality signal you can control from day one.
Readable code also protects you. When you return to your own function on day 11, you will have forgotten why you wrote it on day 3. Clear names, a one-line docstring and type hints answer that question for you.
The free two-week online internship at CareerSwami offers 26 tracks, a free offer letter and a free completion certificate after successful completion. If you pick a Python or backend track, the checklist below is a good way to keep your submissions tidy.
The pre-commit Python style checklist
Run through these five groups before every commit. Each item is a yes or no question, so you can finish the whole list in under five minutes once the tools are installed.
Group 1: Layout and PEP 8 basics
- Indentation is four spaces, with no tabs mixed in.
- Lines stay within 79 characters, or within the limit your team has agreed (many teams use 88 or 100). Pick one and configure your tools to match.
- Imports sit at the top, one per line, grouped as standard library, third-party, then local modules.
- Two blank lines separate top-level functions and classes; one blank line separates methods.
- Spaces surround operators and follow commas, but there are no spaces inside brackets or before call parentheses.
- No unused imports, no unused variables, and no commented-out code blocks left behind.
Group 2: Naming
- Functions and variables use
snake_case. - Classes use
CapWords. - Constants use
UPPER_SNAKE_CASEat module level. - Names describe meaning, not type:
pending_orders, notlstordata2. - Boolean names read like questions:
is_active,has_stock. - No single-letter names except short loop counters, and never
l,OorI.
Group 3: Docstrings and comments
- Every module, public class and public function has a docstring in triple double quotes.
- The first line is a short summary in the imperative mood: “Return the total price”, not “This returns…”.
- Functions with non-obvious inputs document arguments, return values and raised exceptions.
- Comments explain why, not what. If a comment restates the code, delete it or rename something.
Group 4: Type hints
- All function parameters and return values are annotated, including
-> None. - Collections are parameterised, such as
list[str]ordict[str, int]. - Values that can be missing use
X | None(Python 3.10 and later) orOptional[X]for older versions. - You avoid
Anyunless you can state why.
Group 5: Linters and formatters
- A formatter such as Black or Ruff’s formatter has been run, so you never argue about spacing by hand.
- A linter such as Ruff or Flake8 reports zero warnings, or each remaining one is deliberately silenced with a reason.
- A type checker such as mypy or Pyright runs without new errors on the files you changed.
- Your tests, if any exist, pass after the formatting changes.
Free 2-Week CareerSwami Internship
Online, 14 days, with a free offer letter and a free completion certificate once you finish the work. Check with your college that it fits your requirement before you enrol.
Scorecard: rate your module before you commit
Use this table as a self-review. Score each row 0 (not done), 1 (partly) or 2 (fully done). A perfect module scores 20.
| Check | What a 2 looks like | Tool that helps |
|---|---|---|
| Formatting | Formatter run, no manual spacing edits needed | Black or Ruff format |
| Line length | No line exceeds the agreed limit | Flake8 / Ruff |
| Import hygiene | Grouped, sorted, none unused | Ruff (isort rules) |
| Function naming | Verb-led snake_case names |
pep8-naming plugin or review |
| Variable naming | Every name says what it holds | Manual review |
| Module docstring | One paragraph on purpose | pydocstyle / Ruff D rules |
| Function docstrings | Summary, args, returns, raises where needed | pydocstyle / Ruff D rules |
| Type hints | All signatures annotated | mypy / Pyright |
| Error handling | No bare except:; specific exceptions |
Flake8 / Ruff |
| Function size | Each function does one job and fits on one screen | Manual review |
Interpret your total simply: 18 to 20 means ready to commit; 14 to 17 means fix the lowest rows first; below 14 means pause and tidy the module before anyone else reads it.
Before and after: cleaning up a small order-service module
The two snippets below are illustrative. They were written to demonstrate style changes and have not been executed or tested. The module is a tiny backend helper that calculates an order total with a discount.
The messy version
import os,sys
import json
def calc(l,d):
t=0
for i in l:
t=t+i['p']*i['q']
if d>0:
t=t-(t*d/100)
return t
def getUser(id):
try:
f=open('users.json')
u=json.load(f)
return u[id]
except:
return None
Problems a reviewer would notice: unused imports (os, sys), several imports on one line, cryptic names (l, d, t), a camelCase function name, a bare except, a file that is never closed, no docstrings and no type hints.
The cleaned version
"""Helpers for pricing orders and looking up users."""
import json
from pathlib import Path
from typing import TypedDict
USERS_FILE = Path("users.json")
class OrderItem(TypedDict):
price: float
quantity: int
def calculate_order_total(
items: list[OrderItem], discount_percent: float = 0.0
) -> float:
"""Return the order total after applying a percentage discount.
Args:
items: Order lines, each with a price and a quantity.
discount_percent: Discount from 0 to 100. Defaults to no discount.
Returns:
The discounted total as a float.
"""
subtotal = sum(item["price"] * item["quantity"] for item in items)
if discount_percent > 0:
subtotal -= subtotal * discount_percent / 100
return subtotal
def get_user(user_id: str) -> dict | None:
"""Return the user record for user_id, or None if it cannot be found."""
try:
with USERS_FILE.open() as users_file:
users = json.load(users_file)
except (FileNotFoundError, json.JSONDecodeError):
return None
return users.get(user_id)
What each change fixed
- Imports: unused ones removed, one per line, standard library only.
- Names:
calcbecamecalculate_order_total;getUserbecameget_user;l,d,tbecameitems,discount_percent,subtotal. - Docstrings: the module and both functions now explain themselves.
- Type hints: a
TypedDictdocuments the shape of an order line, and signatures show what goes in and out. - Safety: the file is opened with a context manager, the bare
exceptis replaced with two specific exceptions, and a missing key now returnsNonethrough.get. - Behaviour note: the second version changes behaviour slightly for unreadable files and missing keys. Mention such changes in your commit message so a reviewer is not surprised.
Setting up the tools once so the checklist runs itself
Manual checking fails when you are tired. Automate what you can.
- Create a virtual environment for the project and install your formatter, linter and type checker into it.
- Add a small configuration section in
pyproject.tomlthat sets line length and enabled rule groups, so everyone on the project gets the same results. - Install the
pre-commitpackage and add a.pre-commit-config.yamlthat runs the formatter and linter on staged files. - Run the hooks on all files once, review the diff, and commit the formatting change separately from your logic changes.
- Keep the type checker as a manual step at first if it is slow; add it to the hook later.
Check each tool’s own documentation for current setup syntax, since options and rule names change between versions.
A 14-day plan for building the style habit
| Days | Focus | Output |
|---|---|---|
| 1-2 | Environment, formatter and linter installed; read PEP 8 once | Working config and a clean “hello world” commit |
| 3-4 | Naming and import discipline on your first small function | Commit with zero linter warnings |
| 5-6 | Docstrings for every public function | Module with a docstring checker passing |
| 7-8 | Type hints and a type checker on your main module | No type errors on changed files |
| 9-10 | Pre-commit hooks running automatically | Hook config committed |
| 11-12 | Refactor long functions; tidy error handling | Scorecard of 18 or above |
| 13 | Self-review using the scorecard; write a clear README section | Final cleanup commit |
| 14 | Submit work and keep a short before/after note for your portfolio | Submission-ready repository |
Style mistakes that make internship code look careless
- Formatting by hand. It wastes time and produces inconsistent results. Let the formatter decide.
- Silencing warnings wholesale. A blanket
noqahides real problems. Silence a specific rule on a specific line, and say why. - Docstrings that repeat the name. “Gets user” above
get_useradds nothing. Describe the return value and the failure case. - Type hints that say
Anyeverywhere. They satisfy the checker but tell the reader nothing. - Mixing a reformat with a logic change. A reviewer cannot see what really changed. Commit them separately.
- Chasing perfection over delivery. If the function is wrong, perfect style will not rescue it. Use the checklist after the code works.
Central University of Haryana students: placing your Python practice alongside CUH’s own processes
CUH describes itself as one of the new central universities set up under the Central Universities Act, 2009, and it runs its programmes through its own schools, including Engineering & Technology and Interdisciplinary and Applied Sciences, according to its official About page. For you, that means rules on internships are most likely issued by the university rather than by an outside affiliating body, though that is an inference and not a verified rule.
The university’s Training and Placement Cell website lists contact details and sections for students and departmental placement coordinators. Its “For Students” menu appears to include an Internship Format Letter page and a Placement Policy page; these come from menu listings, so read the pages themselves before relying on them.
Timing matters too. The CUH homepage carries notices that odd-semester term-end examinations are scheduled for December 2026 to January 2027, and the Academic Calendar page links 2026-27 calendars. Since a 14-day internship needs steady daily effort, compare your internship dates against those calendars so exam preparation does not collide with your final submission days.
What is not confirmed here: whether CUH counts an online internship for credit, what documents it expects, or how your school evaluates it. Do not assume any of that. A tidy repository will also be useful evidence if your department asks what you built.
Verification steps for CUH students planning a Python internship
- Open the Internship Format Letter page on the Training and Placement Cell site and note whether it applies to online internships.
- Read the Placement Policy page for any rule about internships, and save the version or date shown.
- Email your department’s placement coordinator, asking in writing whether an online internship is recognised and what proof they need.
- Download the 2026-27 academic calendar PDF for your programme and mark the exam and break dates against your 14 days.
- Check your programme’s syllabus on the university’s Student Corner page to see whether a Python or backend course or project requirement exists.
- Keep the written replies, because you may need them if a rule is applied differently later.
Frequently Asked Questions
Do I need to follow PEP 8 exactly?
Follow it by default, and let a formatter handle most of it. If a project sets its own line length or rules, the project’s configuration wins. Consistency within the codebase matters more than any single number.
Which linter should a beginner start with?
Ruff is a common choice because it combines linting, import sorting and formatting in one tool. Flake8 with Black is also widely used. Pick one setup, configure it once and stick with it for the whole internship.
Are type hints required in Python?
No, Python does not enforce them at runtime. They help readers and type checkers catch mistakes early, and many backend teams expect them on function signatures, so adding them is good practice.
How detailed should a docstring be?
A one-line summary is enough for simple functions. Add argument, return and exception sections when the behaviour is not obvious from the signature, such as when a function can return None or raise an error.
Should I reformat old code in the same commit as a new feature?
No. Make the formatting commit first, then the feature commit. Reviewers can then skim the formatting changes and focus on the logic.
Will clean code help me get an internship certificate?
CareerSwami offers a free completion certificate after successful completion of its free two-week online internship. Clean, well-documented work makes it easier to show what you did, but the certificate depends on completing the programme, not on style scores.
Does CUH accept an online internship for academic credit?
That is not verified here. Ask your department or placement coordinator in writing and read the university’s internship and placement pages before assuming credit or recognition.
What if my linter reports hundreds of warnings on existing code?
Run the formatter first, since it clears most of them. Then fix the rest in groups, starting with unused imports and bare exceptions, and only silence a rule when you can explain why.
Related Python & Backend Engineering guides
- Rayat Bahra University Students: Mastering Authentication Basics in a Backend Internship
- Charutar Vidya Mandal University Students: Teamwork Rules for Your First Backend Sprint
- Mandsaur University Students: Deploying a Python API for the First Time on a Free Tier
- All Python & Backend Engineering internship guides
Ready to put this into practice?
Join the free two-week CareerSwami online internship in Python & Backend Engineering. The internship, the offer letter and the completion certificate are free.














