DEV Community

Cover image for How To Write Better Python Code?

How To Write Better Python Code?

Priyansi on May 19, 2020

We all love Python. It’s easy to write and understand but that doesn’t give us the right to abuse a wonderful language by ignoring the rules and w...
Collapse
 
thijs0x57 profile image
thijs0x57

Very useful article, I just started using Python from a very heavy OOP background

Collapse
 
iiverveii profile image
Priyansi

Good luck learning Python! May you become embrace your inner Pythonista.

Collapse
 
muhammadaadil50 profile image
BADSHAH

This is a vast topic.. It needs much concentrations more than explained.. Thanks.. I am shocked at some point even as Intermediate pythonic programmer.. I think you must create regular series beginning to advance pythonic coding.. It will be pleasure for us.. If possible it would be highly appreciated..

Collapse
 
chrisgreening profile image
Chris Greening

Yessss really loved this article, everytime I learn a more pythonic way of doing something I feel the power surge through my bones. Likewise, every time I have to work in another language that doesn't have listcomp's or other syntax tricks that I've taken for granted I get very, very sad lol

Collapse
 
djamaile profile image
Djamaile

You said no classes, but what would you recommend for repeating arguments? Currently I am using dataclasses for that.

Collapse
 
iiverveii profile image
Priyansi

I never said 'no classes'. Obviously, they have their place like in your case. I said prefer functions over classes and group similar functions into modules rather than merely use a class for behavior grouping :)

Collapse
 
djamaile profile image
Djamaile

Aha thanks, happy coding😉.

Thread Thread
 
iiverveii profile image
Priyansi

You too :D

Collapse
 
cereal84 profile image
Alessandro Pischedda

Nice article.

In list comprehensions example, on "bad code", is missing 'value' in append() method.

Collapse
 
iiverveii profile image
Priyansi

Thank you for pointing that out! Fixed it :)

Collapse
 
rodrigoghiraldeli profile image
Rodrigo Ghiraldeli

Thank you very much for this article! :D

Collapse
 
iiverveii profile image
Priyansi

Thank you for taking the time to read it :)

Collapse
 
sivakumarskr profile image
Sivakumar R

A good refresher article for me. Good one.

Collapse
 
iiverveii profile image
Priyansi

Thank you :)