---
title: "Discussion on \"Quick Python Refactoring Tips\" | Hashnode"
description: "Discussion on \"Quick Python Refactoring Tips\". 8 quick Python refactoring tips for cleaner and more pythonic code."
url: "https://hashnode.com/posts/quick-python-refactoring-tips/60f9596c74648858f4bb4d1e"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Quick Python Refactoring Tips](https://patloeber.hashnode.dev/quick-python-refactoring-tips?utm_source=hashnode&utm_medium=feed)

8 quick Python refactoring tips for cleaner and more pythonic code.

Jul 22, 2021 · 5 min read · patloeber.hashnode.dev  
Updated Dec 12, 2021  
Read the article

-   [#python3](https://hashnode.com/tag/python3)
-   [#python](https://hashnode.com/tag/python)
-   [#python-beginner](https://hashnode.com/tag/python-beginner)

## Written by

[Patrick Loeber](https://hashnode.com/@patloeber)

@patloeber

  
[View profile](https://hashnode.com/@patloeber)

Creating content about Python and ML

## Responses 2

Markdown supported · ⌘↵ to post

[Sérgio Rafael Siqueira](https://hashnode.com/@sergiors)

[Nov 17, 2021](https://hashnode.com/posts/quick-python-refactoring-tips/60f9596c74648858f4bb4d1e/comment/61954d1d0b25eb28701f4ff5)

On 6 and 7 you can remove the else, because in if condition has return statement .

[Patrick Loeber](https://hashnode.com/@patloeber)

[Nov 18, 2021](https://hashnode.com/posts/quick-python-refactoring-tips/60f9596c74648858f4bb4d1e/comment/61954d1d0b25eb28701f4ff5#reply-61960c6490fac127e6ea5d82)

yep good point!

[Ahmed Sadman Muhib](https://hashnode.com/@ahmedsadman)

[Jul 23, 2021](https://hashnode.com/posts/quick-python-refactoring-tips/60f9596c74648858f4bb4d1e/comment/60fab45318fbbb77c946316d)

Love your writing style. Really helpful tips. Although, I have slight disagreement with point 7. If your variables are named properly, it should be understandable regardless of where it is assigned. In many cases your other team members would want to find all the assignments in the same place, don't you agree?

[Patrick Loeber](https://hashnode.com/@patloeber)

[Jul 23, 2021](https://hashnode.com/posts/quick-python-refactoring-tips/60f9596c74648858f4bb4d1e/comment/60fab45318fbbb77c946316d#reply-60fb10ef31552277811ab7c2)

Thanks for your feedback! Hmm but why define it somewhere where it's not used? Then you have to search for the next location where it's used...

[Ahmed Sadman Muhib](https://hashnode.com/@ahmedsadman)

[Jul 23, 2021](https://hashnode.com/posts/quick-python-refactoring-tips/60f9596c74648858f4bb4d1e/comment/60fab45318fbbb77c946316d#reply-60fb12aa31552277811ab811)

[Patrick Loeber](https://hashnode.com/@patloeber) When other people work on your code it's not always necessary to know how the variable is assigned, rather the name should define what it's doing. I think it falls under individual preference so it's not actually a refactor.

[Patrick Loeber](https://hashnode.com/@patloeber)

[Jul 23, 2021](https://hashnode.com/posts/quick-python-refactoring-tips/60f9596c74648858f4bb4d1e/comment/60fab45318fbbb77c946316d#reply-60fb244931552277811ab9b1)

Yes agree. Variable names are much more important anyway :)
