Learn useful tricks and concepts to write smarter scripts and prevent bad errors in Python.
Use get() with dictionaries
In Python, dict...
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
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? ")
😎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.
totally agree with you on that point
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
Great article.
import pandas as np
(seen on twitter)
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.
good idea, noted!
Note that
is None
is idiomatic check for None, probably makes a good additionCool stuff :)
Had no idea about the first point :D
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.
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)