DEV Community

Python pro tips

spO0q 🐒 on July 04, 2020

Learn useful tricks and concepts to write smarter scripts and prevent bad errors in Python. Use get() with dictionaries In Python, dict...
Collapse
 
proteusiq profile image
Prayson Wilfred Daniel • Edited

Good stuff. An addition could be instead of just doing … = input(), we add a useful message e.g. …. = input("How many Ship do you need to learn C? ") 😎

Collapse
 
paddy3118 profile image
Paddy3118

You state "Write Object Oriented code".
You should learn it, and learn when to use it or not. Sometimes a function is all you need.

Collapse
 
spo0q profile image
spO0q 🐒

totally agree with you on that point

Collapse
 
epogrebnyak profile image
Evgeny Pogrebnyak

as an idea for exercide - instead of a class with methods, write a dataclass and functions that operate on it, see what is cleaner and where would you prefer either

Collapse
 
muhimen123 profile image
Muhimen

Great article.

Collapse
 
epogrebnyak profile image
Info Comment hidden by post author - thread only accessible via permalink
Evgeny Pogrebnyak


import pandas as np

(seen on twitter)

Collapse
 
danielkun profile image
Daniel Albuschat

Thanks Julien! Maybe you can write your next post about recommended code layout and importing from local files? This is super weird with Python IMHO.

Collapse
 
spo0q profile image
spO0q 🐒

good idea, noted!

Collapse
 
epogrebnyak profile image
Evgeny Pogrebnyak

Note that is None is idiomatic check for None, probably makes a good addition

Collapse
 
stefan_stojanovic profile image
Stefan Stojanovic

Cool stuff :)

Had no idea about the first point :D

Collapse
 
paddy3118 profile image
Paddy3118

You mention "Use shorter if statements". I get the sentiment but use a set literal rather than the list as it is better for such lookups, in general.

Collapse
 
epogrebnyak profile image
Evgeny Pogrebnyak • Edited

There is a view, often debated though, that the more if's you have is code, the less is the quality (eg flags in fucntions, avoidable branching, etc)

Some comments have been hidden by the post's author - find out more